Comparing objects using bool operator==

前端 未结 4 1494
说谎
说谎 2021-02-14 05:04

So, after reading some SO questions and answers, i still doesn\'t understand why use

friend bool operator==( BaseClass const &left, BaseClass const &righ         


        
4条回答
  •  后悔当初
    2021-02-14 05:29

    There's nothing wrong per se with the member function, but the free function is more generic. The member function is forced to have the left-hand side operand be of type BaseClass or a child type, while the free function accepts any types that are implicitly convertible to BaseClass, not just types that are part of the inheritance tree.

提交回复
热议问题