Having code
struct node { node(int X , int Y):X(X),Y(Y){}; int X; int Y; friend bool operator ==(const node &X, const node &Y); }; int main() { node one(5,5); node two(5,5); if ( one == two ) { cout << " true " << endl; } return 0; } If i declare operator == as
bool node::operator ==(const node &X, constnode &Y) { return (X.X == X.Y && Y.X == Y.Y); } it requires one argument , however when i declare it as
bool operator ==(const node &X, constnode &Y) { return (X.X == X.Y && Y.X == Y.Y); } It requires two. I know defined by language , first definition requires one argument becouse the second is *this.
And the second definition its outside definition of operator == ( global ) which is not bound to any structure thu it does not pass *this in it.
But it is still defined as "friend" this basicly states ( by first definition ) that member function is friend function of its own class. How is this possible? Why does this compile?
bool node::operator ==(const node &X, const node &Y)would require 3 arguments (member function have impliedthisparameter).X.X == Y.X && X.Y == Y.YnotX.X == X.Y && Y.X == Y.Y