Answer the question
In order to leave comments, you need to log in
How to compare objects?
Let's say I have objects in the array, and there is also a function that takes one object as a parameter. It must go through the array and find an identical object. What is the best way to compare objects in this case?
Answer the question
In order to leave comments, you need to log in
Formulate a condition for the equality of objects, add an appropriate operator to them. PROFIT!
well, if your objects are in the array, write a comparison constructor to them and that's it
Enter comparison operators:
friend bool operator==(const YourClass& left, const YourClass& right);
friend bool operator!=(const YourClass& left, const YourClass& right);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question