• Popular Now

• 12
• 9
• 9
• 13
• 10

Archived

This topic is now archived and is closed to further replies.

This topic is 5134 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi @all, I guess for most of you my problem isn''t a problem at all... but look... I''ve got a class like this :
class StringClass
{
public :

StringClass operator+(StringClass *CString);
StringClass operator+=(StringClass *CString);

};

I''d like to have both operators, + and += in my class, because it would make it much easier for me to work with those Strings. Because the += operator is very similar to the + operator, I tried to use the + operator in my += operator''s function instead of copying all the code.
StringClass operator+(StringClass *CString)
{
StringClass CNewString;
//plz imagine a huge piece of code here

return CNewString;
}

StringClass operator+=(StringClass *CString)
{
StringClass CNewString;
CNewString = this + CString; //doesn''t work... :(

return CNewString;
}

But, somehow it doesn''t work! My compiler tells me that there''s no global binary operator "+" defined... how can I make this one work?

Share on other sites
You forgot to dereference the this pointer. i.e. *this + CString.

James