C++ overloading operators difference between == and <

前端 未结 6 1311
花落未央
花落未央 2021-01-21 17:01

Could anybody explain me what is the difference between overload == and <?

For example, if I use a map:

map         


        
6条回答
  •  时光取名叫无心
    2021-01-21 17:20

    std::map is an ordered container, therefore it needs an operator < to define the order of elements.

    A separate operator == is not needed because it is implemented in terms of operator <, a==b being equivalent to !a

提交回复
热议问题