有没有办法通过使用其他类方法(如read()和write()来覆盖像<<
或>>
这样的流运算符?
例如,
//In the header file
class Customer
{
void read(istream &, Customer &);
istream & operator>>(Customer &) = read();
void write(ostream &, const Customer &);
ostream & operator<<(const Customer &) = write();
}
这是教科书中问题的请求功能,不允许friend
。