Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ template-function -> passing a template-class as template-argument
    primarykey
    data
    text
    <p>i try to make intensive use of templates to wrap a factory class:</p> <p>The wrapping class (i.e. classA) gets the wrapped class (i.e. classB) via an template-argument to provide 'pluggability'.</p> <p>Additionally i have to provide an inner-class (innerA) that inherits from the wrapped inner-class (innerB).</p> <p>The problem is the following error-message of the g++ "gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)":</p> <pre><code>sebastian@tecuhtli:~/Development/cppExercises/functionTemplate$ g++ -o test test.cpp test.cpp: In static member function ‘static classA&lt;A&gt;::innerA&lt;iB&gt;* classA&lt;A&gt;::createInnerAs(iB&amp;) [with iB = int, A = classB]’: test.cpp:39: instantiated from here test.cpp:32: error: dependent-name ‘classA::innerA&lt;&gt;’ is parsed as a non-type, but instantiation yields a type test.cpp:32: note: say ‘typename classA::innerA&lt;&gt;’ if a type is meant </code></pre> <p>As you can see in the definition of method createInnerBs, i intend to pass a non-type argument. So the use of typename is wrong!</p> <p>The code of test.cpp is below:</p> <pre><code>class classB{ public: template &lt; class iB&gt; class innerB{ iB&amp; ib; innerB(iB&amp; b) :ib(b){} }; template&lt;template &lt;class&gt; class classShell, class iB&gt; static classShell&lt;iB&gt;* createInnerBs(iB&amp; b){ // this function creates instances of innerB and its subclasses, // because B holds a certain allocator return new classShell&lt;iB&gt;(b); } }; template&lt;class A&gt; class classA{ // intention of this class is meant to be a pluggable interface // using templates for compile-time checking public: template &lt;class iB&gt; class innerA: A::template innerB&lt;iB&gt;{ innerA(iB&amp; b) :A::template innerB&lt;iB&gt;(b){} }; template&lt;class iB&gt; static inline innerA&lt;iB&gt;* createInnerAs(iB&amp; b){ return A::createInnerBs&lt;classA&lt;A&gt;::template innerA&lt;&gt; &gt;(b); // line 32: error occurs here } }; typedef classA&lt;classB&gt; usable; int main (int argc, char* argv[]){ int a = 5; usable::innerA&lt;int&gt;* myVar = usable::createInnerAs(a); return 0; } </code></pre> <p>Please help me, i have been faced to this problem for several days. Is it just impossible, what i'm trying to do? Or did i forgot something?</p> <p>Thanks, Sema</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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