I am writing my first bit of object code in C++, and am having a bit of trouble with operator= overloading.
This is paraphrased from my header file:
and from the cpp file:
Now, the problem is when I try to call say:
Within the operator= fucntion, the value is MC is created correctly, however, it just doesn't get assigned to MC1, which is still as initialised in the default constructor.
Please help a newbie to find the problem.
This is paraphrased from my header file:
Code:
class MyClass
{
public:
MyClass ( const char* );
MyClass operator= ( const char* );
...
}
and from the cpp file:
Code:
MyClass :: MyClass ( const char* rhs )
{
\\ do something and assign it to the new MyClass
}
MyClass MyClass :: operator= ( const char* rhs )
{
MyClass MC(rhs); \\MC is created as desired
return MC;
}
Now, the problem is when I try to call say:
Code:
MyClass MC1, MC2;
MC1 = "abcdef";
Please help a newbie to find the problem.