Please help to complete this execution of an assignment overloading function.
Here is the instruction:
Assignment operator (=) which will copy the source string into the destination string. Note that size of the destination needs to be adjusted to be the same as the source.
Both addition (+) and assignment (=) operators need to be capable of cascaded operations. This means String3 = String1 + String2, or String1 = String2 = String3 should work.
Here is my .cpp file:
MyString& MyString::operator=(const MyString& rhs)
{
if(this != &rhs)
{
delete [] String;
String = new char[Size];
for(int i = 0; i < counter+1 ; i++)
{
String[i] = rhs.String[i];
}
}
return *this;
}
It is called in the main.cpp file by:
String1=String2=String3;
I feel as though I am missing something.Help!!
No comments:
Post a Comment