Hi guys, I have a question, now I learning about overloading operators. Now I'll tell you my question. How can gather two objects created by me with overloading operators? I know to compare two objects, but I don't know how to make gathering with two objects.
Not sure I understand the question. What do you mean by "gather two objects"?
A comparison operator compares two objects. The Left Hand Side (LHS), which is the this object and the Right Hand Side (RHS) which is the argument to the function.
1 2 3 4 5 6 7 8 9
bool MyClass::operator == (const MyClass & rhs) const
{ returnthis->somefield == rhs.somefield;
}
MyClass a, b;
if (a == b)
{ // Do something
}