I'm having difficulty writing a friend operator, checkout the code below. The first operator compiles fine, but the second (the “=” operator) gives me a bunch of errors (first of which says “error C2801: 'operator =' must be a non-static member” in VC++ 2003). Is it illegal to define a friend operator for assignment? Thanks.
Code:class A { public: int x; }; class B { public: friend A& operator += (A &a, const B &b) { a.x = 1; return a; } friend A& operator = (A &a, const B &b) { // is this legal? a.x = 2; return a; } };