c++ - Error when using template class as template template-parameter in member variable -
i using templates in c++ project, , i'm having issue when using templated type template template-parameter. think best way describe give example produces error:
template <template<class> class p, typename t> class foo { p<t> baz; }; template <class t> class bar { foo<bar, t> memberfoo; void makefoo() { foo<bar, t>* f = new foo<bar, t>(); } }; foo<bar, int> globalfoo; the declaration of globalfoo causes no error, declarations of memberfoo , f cause compiler error:
error: template argument template template parameter must class template or type alias template
the error occurs when using bar template parameter inside of declaration of bar class, occurs using both clang , g++. seems documented somewhere, googling yields no questions or other documentation.
is use of templates not legal in c++, or misunderstanding how define , use templates? if design architecture not allowed c++11 standard, workaround can use?
the issue incomplete type yielded @ time of instantiation. clang , g++ yield different errors because clang (apparently) doesn't implement c++11 rule injected class name can refer class template when used template template parameter (igor's suggestion doesn't work btw.) changing bar ::bar fixes error, makes clang point out incomplete error g++ does. changing baz p<t>* allows compile.
n.b. though compiles, undefined behavior. suggest redesigning classes.
Comments
Post a Comment