Let’s say I have this:
struct coor
{
int x;
int y;
COORD operator=(coor c)
{
COORD C={c.x,c.y}
return C;
}
}
and I needed to do:
coor c={0,0};
COORD C=c;
I could add operator overloading to coor, but how do you do that to return to left side?
Operator
=must assign values to members of the object itself. The return value is there just to makea = b = cand similar things work. In your case it is irrelevant. Also, if you haveA = B, the=defined inAwill be used and if you haveB = A, the=inBis used.What you need is to write a
=inCOORDthat takescoorparameter and updates members of this.And the following does not call operator
=:It calls a matching constructor.
and the operator= MUST return
*thisfor things like this:a=b=c=dto work but this is conventional