Comparison operator overloaded member function, form and function in the form of friend

Friend member function operator overloading

No functional differences, sometimes binary operator overloading to friend function in more flexible than the member function , for example:

c2 (plural) is equal to 1 (int) + c1 (plural)

c2 = 1 + c1;

If you use the "+" member function overloading, the compiler will complain

The compiler will be interpreted as the right formula

1.operator + (c2);

1 is an int data type can not be. "" Operation, the UF yuan function overloading would not have this problem

operator + (1,c1)

Guess you like

Origin www.cnblogs.com/Waker-WH/p/10959177.html