Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我们可以在 C++ 中声明这样的函数吗:
int operator + (int , int);
您的回答将不胜感激!
谢谢
您不能重新定义内置运算符。运算符重载旨在允许您扩展语言,而不是更改它。重载运算符的至少一个参数必须是用户定义类型(类或枚举类型)或对用户定义类型的引用。
是:您可以将整数和浮点数传递给重载函数
否:当内置类型位于表达式的两侧时,您不能重载/覆盖内置类型的运算符。
不,我们不能重载整数或浮点类型,因为重载意味着改变现有运算符的工作或使它们与对象一起工作 int 是单个成员而不是对象。