About overloading operators

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
{  return this->somefield == rhs.somefield;
}

  MyClass a, b;

  if (a == b)
  {  // Do something
  }


Is this what you mean?
Last edited on
I was a little confused, I wanted to say how to compare more objects. And your example was the solution. Ty a lot :D
Last edited on
Topic archived. No new replies allowed.