这就是我想要实现的。叶组件继承Component<ParentT>
,其他人将继承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;
...
};
但问题是模板参数入门重新声明。我不能将第二个继承第一个,因为第二个继承了第一个。
error: redeclared with 2 template parameter(s)
note: previous declaration ‘template class Component’ used 1 template parameter(s)
目前忽略可变参数模板,模板具有固定数量的参数;一个Component <>'不能同时具有一个和两个参数。这看起来像一个[XY问题](http://meta.stackexchange.com/q/66377/166663) - 你究竟想要完成什么? – ildjarn 2012-08-05 06:31:31
那么建模它的好方法是什么? '组件'? –
2012-08-05 06:32:40
这取决于 - 为什么你要基地和孩子有相同的名字?给他们不同的类型名称,你没有问题。 – ildjarn 2012-08-05 06:33:12