Operator = must assign values to members of the object itself. The return value is there just to make a = b = c and similar things work. In your case it is irrelevant. Also, if you have A = B, the = defined in A will be used and if you have B = A, the = in B is used.
What you need is to write a = in COORD that takes coor parameter and updates members of this.
Where it is declared is of no relevance, it doesn't make the operator= implementation any more correct.
What you probably want is a COORD conversion operator and a conversion constructor.
And the following does not call operator=: COORD C=c;
It calls a matching constructor.
struct coor
{
int x;
int y;
coor() { x = 0 ; y = 0 ; }
voidoperator=(coor c)
{
x = c.x;
y = c.y;
}
};
I suppose this is the right way to do it ..
there should be no return type and secondly the value should be assigned to the variable from the variable that is passed in the object .
Also you will need constructor on this to initialize the variable .