如何用成員函數的方式重載輸出操作符<<
4 回答

楊__羊羊
TA貢獻1943條經驗 獲得超7個贊
類里面聲明用
class obj
{
public:
int x,y;
friend ostream& operator<<(ostream& os,obj& rhs);
}
實現的時候用:
ostream& operater<<(ostream& os,obj& rhs)
{
os<<rhs.x<<rhs.y;
return os;
}
添加回答
舉報
0/150
提交
取消