So, I need to make a mixin class that would encapsulate children of some derived class. The derived class should inherit from the mixin while providing a container template as a template template argument for the mixin.
The desired code is somewhat like that:
/*template definition*/
template<template<typename T, typename A> class C>
class HasChildren {
protected:
C<T, A> m_children;
/* whatever */
};
It has an array of issues:
- When trying to instantiate this class like
HasChildren<std::vector<int>>(just for testing), compiler saysexpected a class template, got ‘std::vector<int>’. Clearly, I'm not passing a template template. I would like to know what exactly I'm trying to pass. - For
C<T, A> m_children;compiler says thatTandAare out of scope. When I addtypenamekeyword for them, the error changes toerror: wrong number of template arguments (1, should be 2). I would like to know whyTandAare out of scope and why addingtypenameleads to this error.
std::vector<int>, instead of a template,std::vector.template<typename T, typename A>does not make the template template useTandA. They are just for documentation and can be removed.Example:
If you prefer to instantiate
HasChildrenlike you originally tried, by usingHasChildren<std::vector<int>>, you can do that by specializingHasChildren: