Why isn't operator overloading for pointers allowed to work?

后端 未结 9 2039
鱼传尺愫
鱼传尺愫 2020-12-03 14:08

As per the comment under this answer, references were introduced primarily to support operator overloading which quotes Bjarne Stroustrup:

References

9条回答
  •  独厮守ぢ
    2020-12-03 15:05

    Operators can't be overloaded when both types involved are built-in types (like int, float or any kind of pointer). You can overload operator for one class and one primitive type (or you can just use type conversion). For example you can add std::string and const char *.

提交回复
热议问题