Note that there are some explanatory texts on larger screens.

plurals
  1. POinheriting from a class template with a default argument
    primarykey
    data
    text
    <p>I've created a class looking something like this. The key is that it's got a main template argument plus a template base class with a default. There is also a templated copy constructor...</p> <pre><code>struct default_base{}; template &lt;typename T, typename TBase=default_base&gt; class some_class : public TBase{ public: some_class(){} template &lt;typename U, typename UBase&gt; some_class(const some_class&lt;U,UBase&gt;&amp; u){ T t(U()); } }; int main(){ some_class&lt;int&gt; a; return 0; } </code></pre> <p>I'm getting this annoyingly vague compiler error, and haven't been able to spot my error...so my question is - what's really wrong? I'm using gcc 4.8.1.</p> <pre><code>g++ -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\stuff.o" "..\\src\\stuff.cpp" ..\src\stuff.cpp: In constructor 'some_class&lt;T, TBase&gt;::some_class(const some_class&lt;U, UBase&gt;&amp;)': ..\src\stuff.cpp:87:10: error: default argument for template parameter for class enclosing 'T t(U (*)())' T t(U()); ^ ..\src\stuff.cpp: In function 'int main()': ..\src\stuff.cpp:104:16: error: wrong number of template arguments (1, should be 2) some_class&lt;int&gt; a; ^ ..\src\stuff.cpp:82:7: error: provided for 'template&lt;class T, class TBase&gt; class some_class' class some_class : public TBase{ ^ ..\src\stuff.cpp:104:19: error: invalid type in declaration before ';' token some_class&lt;int&gt; a; </code></pre> <p>Edit: Spot on answers, Cheers :-) Even if I still think it should compile... this compiles...</p> <pre><code>template &lt;typename T&gt; struct some_other_class{ some_other_class(){} template &lt;typename U&gt; some_other_class(){ T t(U()); } }; </code></pre>
    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.
    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