+ 2
Why assignment operator cannot be overloaded as a friend function?
5 Réponses
+ 2
The syntax of overloading the assignment operator is the following:
Foo& operator=(const Foo &b)
{
// copy members
this->member = b.member;
return *this;
}
You can see that there is only one parameter.
But assignments consist out of two parts: a = b
The first operand ( a ) is included indirectly as part of the current instance. You access it with this.
Thus it has to be a member function and not an external friend function.
0
lllpllp
0
It varies & depends
0
@harish please explain how it varies and depends????
- 1
do u have fb