关于运算符的成员函数左右操作数问题

来源:互联网 发布:java类方法实例化 编辑:程序博客网 时间:2024/05/22 07:54


Two elements operator

任何二元运算符要求左、右操作数:
ObjectL op ObjectR

1> 当重载为成员函数时,左操作数由this指针传递,右操作数由参数ObjectR传递.

So IO operators should be overloading as nonmember functions.

重载为友员函数时,左右操作数都由参数传递.

2> Index operator should be overloading as member functions.Because of nonmember functions have no this pointer,so we can not change the member of classes.