Search code examples
c++scriptingautomationcomparison-operators

Comparison (operator's overloading) of large and sophisticated structures in c++


We must face serious issue while prepraing my project and working on code in c++. My code is build on multiple structures/classes where one is included in another. Finaly i will have to compare all these structures between themselves. In this case it is impossible (or requres terrible effort) to overload comparison operators for everything. Do you perhaps have any idea how to approach this issue? I considered writing a script which would go through all classes and subclasses and add required operators to avoid writing them. Have you ever encountered this and found solution? I am thankful for all advices in advance.

Kind Regards,


Solution

  • If you can implement a common interface in each of the classes that provides the tools necessary to compare the various different classes. In this way you can write just one single operator== which operates on the interfaces without needing to know about the low level details.