开发者

Template class assignment operator class

I have a TemplateArray and a CharArray class.

How do I make it so the templatearray's assignment operator only copies in from the chararray class when the templatearray is of the same type (I.E. char) or similar type (I.E. unsigned char) to chararray?

TemplateArray and CharArray are functionally the same (except CharArray can handle NULL terminated strings).

For example:

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 t开发者_如何转开发o CharArray
    //Both classes are functionally the same, except CharArray is chars only
}


It looks like you need a specialization of 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜