What would happen if the overloaded assignment operator returns an object by value rather than by reference?
Meaning, the 'operator=' is implemented like below:
rather than like this:
What is it's impact to the program aside from the fact that is is poorly designed?
Rome did not create a great empire by having meetings, they did it by
killing all those who opposed them.
- janvier -
Meaning, the 'operator=' is implemented like below:
Code:
// Assume there is class named 'B' with a single member
// variable named 'int i'
B B::operator=( const B& b )
{
B my_b ;
my_b.i = b.i ;
return ( my_b ) ;
}
rather than like this:
Code:
B& B::operator=( const B& b )
{
// checking for self-assignment ommitted
this->i = b.i ;
return *this ;
}
What is it's impact to the program aside from the fact that is is poorly designed?
Rome did not create a great empire by having meetings, they did it by
killing all those who opposed them.
- janvier -