开发者

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

开发者 https://www.devze.com 2023-02-11 11:58 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号