Note that there are some explanatory texts on larger screens.

plurals
  1. POTemplate Type input used as Template Type for Member Property C++
    text
    copied!<p>So I am trying to have one template class be a container (that will later operate on) a set of contained classes, also generated from a template, and stored in a vector. </p> <p>The abstracted form of what I'm trying to do would look like this:</p> <pre><code>template &lt;typename T, size_t numberofapples&gt; class Apples { public: Apples(std::vector&lt;T&gt; appleinfo1, std::vector&lt;T&gt; appleinfo2); protected: std::vector&lt;T&gt; apple_stats; std::vector&lt;T&gt; info1, info2; }; template &lt;typename T, size_t numberofapples&gt; Apples&lt;T, numberofapples&gt;::Apples(std::vector&lt;T&gt; appleinfo1, std::vector&lt;T&gt; appleinfo2) : apple_stats(numberofapples, 0){ for (size_t i = 0; i &lt; numberofapples; ++i) { apple_stats[i] = rand(); } info1 = appleinfo1; info2 = appleinfo2; } template &lt;typename T, typename FruitType, size_t numberoffruitperbranch&gt; class Tree { public: Tree(size_t numberofbranches, std::vector&lt;T&gt; commonfruitinfo1, std::vector&lt;T&gt; commonfruitinfo2); protected: std::vector&lt;FruitType&lt;T, numberoffruitperbranch&gt; &gt; branchset; }; template &lt;typename T, typename FruitType, size_t numberoffruitperbranch&gt; Tree&lt;T, FruitType, numberoffruitperbranch&gt;::Tree(size_t numberofbranches, std::vector&lt;T&gt; commonfruitinfo1, std::vector&lt;T&gt; commonfruitinfo2) : { typename FruitType&lt;T, numberoffruitperbranch&gt; single_fruit(fruitinfo1, fruitinfo2); branchset.resize(numberofbranches, single_fruit); //in the un-abstracted version that has nothing to do with fruit, I'd then iterate over the vector and run some internal code on each one } </code></pre> <p>The goal is that I'd like to be able to do something like:</p> <pre><code>Tree&lt;double, Apples, 10&gt; MyFirstTree(5, vectorofdata, secondvectorofdata); </code></pre> <p>At the moment, however, the compiler is telling me that FruitType is not a valid template inside the constructor function. In fact, everything inside the constructor appears to be out of scope and is being flagged, but I can't figure out why. The unabstracted version also does have a number of other member variables and functions, but the problem is definitely in the constructor of the outer class container. </p> <p>Where am I going wrong/how could this be done better?</p> <p>edit: fixed some compiler errors (I think) which I noticed were different from this trivial example that I did not make in the actual application</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload