これはコンパイルされ、私が理解している限り、あなたが好きなことをします:
#include <vector>
class NoneT {};
template <typename ParentT,typename ChildT=NoneT>
class Component: public Component<ParentT>{
protected:
typedef std::vector<ChildT*> CollectionT;
};
専門NoneT
:
template<>
template<typename T>
class Component<T,NoneT>{
protected:
typedef Component<T> ParentComponentT;
};
int main(){
typedef Component<double> someT;
typedef Component<double,int> someT2;
typedef Component<double,void> someT3;
}
someT
あります。ParentComponentT
_someT2
CollectionT
編集:
以下のコメント/質問への回答:typename ChildT=noneT
デフォルトChildT
が になることを意味しますnoneT
。したがって、2 番目のテンプレート引数が指定されていない場合は、noneT
型が使用されます。
次に、特殊化により、その引数が 1 つのバージョンのクラス コンテンツが定義されます。
EDIT2:
コンポーネントを基本クラスとして使用していることをチャットから知っているので、代わりに次のようなものをお勧めします
class myclass: public Component<Section, Line>
多重継承を使用できます
class myclass: public ParentComponent<Section>, CollectionComponent<Line>
と
template <typename T>
class ParentComponent{
protected:
typedef Component<T> ParentComponentT;
};
template <typename ChildT>
class CollectionComponent {
protected:
typedef std::vector<ChildT*> CollectionT;
};