+ 2

Why assignment operator cannot be overloaded as a friend function?

15th May 2017, 5:58 AM
Ruchi sinha
Ruchi sinha - avatar
5 odpowiedzi
+ 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.
15th May 2017, 6:19 AM
lulugo
lulugo - avatar
0
lllpllp
16th May 2017, 1:15 PM
Duy Lê
Duy Lê - avatar
0
It varies & depends
18th May 2017, 11:12 AM
Harsh
Harsh - avatar
0
@harish please explain how it varies and depends????
18th May 2017, 3:03 PM
Ruchi sinha
Ruchi sinha - avatar
- 1
do u have fb
17th May 2017, 6:10 PM
Vamshi Merugu