|
-
February 20th, 2007, 02:43 PM
#1
operator overload problem
I make a "+" overload for my class as what CString does but found it cannot give the right result.
Here is my code:
CmyClass& operator +(CmyClass& a, CmyClass& b)
{
CmyClass c(...);
// assign a+b value to c
return c;
}
and then if i run
CmyClass a, b, c;
c = a+b;
give a wrong c result;
I have thought about c is supposed to have only local lifetime, but CString does the same
this is what CString does:
CString AFXAPI operator+(const CString& string1, const CString& string2)
{
CString s;
s.ConcatCopy(string1.GetData()->nDataLength, string1.m_pchData, string2.GetData()->nDataLength, string2.m_pchData);
return s;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|