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.
本文探讨了C++中二元运算符的重载方式,特别是作为成员函数与非成员函数的区别。此外,还讨论了索引运算符为何更适合重载为成员函数的原因。
2218

被折叠的 条评论
为什么被折叠?



