阅读背景:

操作符重载:成员函数还是非成员函数?

来源:互联网 

I read that an overloaded operator declared as member function is asymmetric because it can have only one parameter and the other parameter passed automatically is the 'this' pointer. So no standard exists to compare them. On the other hand, overloaded operator declared as a friend is symmetric because we pass two arguments of the same type and hence, they can be compared. My question is that when i can still compare a pointer's lvalue to a reference, why are friends preferred? (using an asymmetric version gives the same results as symmetric) Why do STL algorithms use only symmetric versions?I read that an overloaded operator declared as




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: