2011-09-11 20 views
0

私はTemplateArrayクラスとCharArrayクラスを持っています。テンプレートクラスの代入演算子クラス

templatearrayの代入演算子は、templatearrayがchararrayと同じ型(I.E. char)または類似の型(I.E. unsigned char)である場合にのみchararrayクラスからコピーされます。

TemplateArrayとCharArrayは機能的に同じです(ただし、CharArrayはNULLで終了する文字列を処理できません)。例えば

template<typename TemplateItem> 
TemplateList & TemplateList<TemplateItem>::operator=(const CharArray &ItemCopy) 
{ 
    //How do I only copy when TemplateList is of type char (or similar unsigned char) 
    //IE is same/similar to CharArray 
    //Both classes are functionally the same, except CharArray is chars only 
} 
+0

のコード例が1000個の言葉の価値がある。) –

+0

わかりました。私は多くのヘッダーファイルからコピー&ペーストすることはできませんが、私は関数の行を引用します。 – SSight3

+0

私はあなたが "char"のためのテンプレートの専門化によってそれを行うことができると思います。そうでなければ、リフレクションまたは他の種類のメカニズムを実装することによってランタイム型の識別のための方法を見つけなければなりません。 – Arunmu

答えて

3

あなたがTemplateList::operator=の特殊化を必要とするように見えます:

template<> 
TemplateList& TemplateList<char>::operator=(const CharArray &ItemCopy) 
{ 
    // Do the copying here, you don't provide enough 
    // information for a practical suggestion 
} 
+0

優秀!ありがとうございました! – SSight3

関連する問題