D
D
deathor2016-02-09 19:03:56
OOP
deathor, 2016-02-09 19:03:56

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

3 answer(s)
V
Vladimir Martyanov, 2016-02-09
@vilgeforce

Formulate a condition for the equality of objects, add an appropriate operator to them. PROFIT!

P
Pavel Kaptur, 2016-02-09
@drem1lin

well, if your objects are in the array, write a comparison constructor to them and that's it

D
Denis Zagaevsky, 2016-02-23
@zagayevskiy

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 question

Ask a Question

731 491 924 answers to any question