Search code examples
c++classtemplatessyntaxtype-parameter

Class template instantiation as type template parameter, syntax?


class XY{};

template<typename typeA>
class A
{
(...)
};
template<typename typeB>
class B
{
(...)
};
(...)
     B<class <class XY>A> * attribute; // <- How can I do that without Syntaxerror

When trying this gcc gives me the following error:

xy.h:19: error: template argument 1 is invalid

How can I avoid that?


Solution

  • The class keyword is only for defining a template class, not for declaring an object. For that, you just need:

    B<A<XY> >* attribute;
    

    Or to spread it out for clarity:

    typedef A<XY> MyA;
    typedef B<MyA> MyB;
    MyB* attribute;