我的意思是,我试图在类中重载 operator<<
像这样
class A {
public:
ostream &operator<<(ostream &os);// which doesnt work
private:
friend ostream &operator<<(ostream &os, const A& a); //Works
int i;
};
Definition
ostream &operator<<(ostream &os, const A& a) {
os<<a.i;
return os;
}
为什么我不能在特定于类的类中重载运算符?还是我错过了什么?或者我是否愚蠢地以这种方式思考?请指教。