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 开发者_C百科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,
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.
精彩评论