Imagine that you have overloaded operator* and operator= for class

来源:百度知道 编辑:UC知道 时间:2024/09/23 04:52:33
Imagine that you have overloaded operator* and operator= for class
A. Does the following expression work? If yes, explain why. If no,
explain what must be done otherwise.
 A a,b;
a *= b;

Why can the operator<< that outputs an object A to an ostream not
be implemented as a member function of A?

最好用英文回答.谢谢.急用

1.应该是错误的。一般在重载中都是使用*=来实现*,boost的Operator就是这样来的。
2.因为如果定义为成员函数的话,那么重载的左操作数就必须是该类的对象,这对于输入输出流运算符来说是不合适的。