This is what I want to achieve. The leaf component will inherit Component<ParentT>, others will inherit Component<ParentT, ChildT>
template <typename T>
class Component{
protected:
typedef Component<T> ParentComponentT;
...
};
template <typename ParentT, typename ChildT>
class Component: public Component<ParentT>{
protected:
typedef std::vector<ChildT*> CollectionT;
...
};
But the problem is Template parameters getting redeclared. and I cannot move the second one above first one because second one inherits first one.
error: redeclared with 2 template parameter(s)
note: previous declaration ‘template class Component’ used 1 template parameter(s)
This compiles and as far as I understand does what you like:
Specialization for
NoneT:someTwill haveParentComponentTandsomeT2will haveCollectionT.EDIT:
Answer to comment/question below:
typename ChildT=noneTmeans that the defaultChildTwill benoneT. So, if no second template argument is given thenoneTtype will be used.The specialization then defines the class content for the that one-argument version.
EDIT2:
Since I know from the chat that you use Component as a base class, I suggest that instead of something like
you could use multiple inheritance
with