SE Does Not Like Dissent
SE Does Not Like Dissent

Reputation: 1815

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 to CharArray
    //Both classes are functionally the same, except CharArray is chars only
}

Upvotes: 0

Views: 694

Answers (1)

Jon
Jon

Reputation: 437326

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
}

Upvotes: 3

Related Questions