Why can some operators only be overloaded as member functions, other as friend functions and the rest of them as both?

后端 未结 4 666
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-04 16:44

Why can some operators only be overloaded as member functions, other as non-member \"free\" functions and the rest of them as both?

What is the rationale behind thos

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 17:08

    Because you can't modify the semantics of primitive types. It wouldn't make sense to define how operator= works on an int, how to deference a pointer, or how an array access works.

提交回复
热议问题