我需要重载的最小运算符集是什么? [英] What is the minimum set of operators I need to overload?
本文介绍了我需要重载的最小运算符集是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
比较的哪个运算符(< =,>,==等)通常作为基本运算符来实现,您可以在使用它们之后实现其余的比较运算符或在类之间进行所有可能的比较?
which operators of the comparison (<=, >, ==, etc.) do You usually implement as your basic operators, which You can after use to implement the rest comparison operators or to make all possible comparisons among the classes?
推荐答案
您可以使用以下等效项在==
和<
方面实现所有六个运算符:
You can implement all six of the operators in terms of ==
and <
using the following equivalencies:
a != b => !(a == b)
a > b => b < a
a >= b => !(a < b)
a <= b => !(b < a)
这篇关于我需要重载的最小运算符集是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文