class A
{
public:
int x, y;
A operator+ (A, B);
};
A A::operator+ (A, B)
{
A c;
c.x = A.x + B.x;
c.y = A.y + B.y;
return c;
}
int main ()
{
A X, Y, Z;
int a, b, c;
//Assuming I set some values to X, Y & b, c:
Z = X + Y;
//Upto here I know this is valid.
a = b+c;
//Will the above line be valid??
}
If it does, then another question:
If I create a second class B, and overload the + operator for it as well, How will the program know which operator to use if I use + in an operation?
So it will recognize them by their types?
And one final questions,
In what way should two classes be related so that one may be able to Add (using the overloaded operator) the Tow classes? Is it even possible?
1 2 3 4 5 6 7 8 9
class A
{
//Something
}
class B
{
//Something as well
}
Now what should be the relation between A & B so that: A+B
Will be valid?