why C++ operator overloading requires “having at least one parameter of class type”?

后端 未结 3 1433
梦如初夏
梦如初夏 2021-02-08 00:18

The chapter 14.1 of \"C++ primer 5th edition\" reads,

An operator function must either be a member of a class or have at least one parameter of class typ

3条回答
  •  臣服心动
    2021-02-08 00:45

    As Bjarne said in Design and Evolution, the goal was to make it easy to extend the language, not to mutate it. If you allowed overloading only builtin types, you would change the language, and allowing that went against the design goals. (For example, it would encourage the formation of mutually incompatible dialects and fracture the community.)

提交回复
热议问题