开发者

Template class assignment operator class

开发者 https://www.devze.com 2023-04-04 05:57 出处:网络
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. cha

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

精彩评论

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

关注公众号