我们可以重载内置类型的运算符,如int或float? [英] Can we overload operators for built-in types like int or float?
本文介绍了我们可以重载内置类型的运算符,如int或float?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们可以在c ++中声明一个这样的函数:
Can we declare a function like this in c++:
int operator + (int , int);
您的答案将不胜感激。
感谢
推荐答案
您无法重新定义内置运算符。操作符重载
旨在允许您扩展语言,而不是更改
。重载操作符
的至少一个参数必须是用户定义的类型(类或枚举类型)或引用
到用户定义的类型。
You cannot redefine a built-in operator. Operator overloading is designed to allow you to extend the language, not to change it. At least one of the parameters of an overloaded operator must be a user defined type (class or enum type) or a reference to a user defined type.
这篇关于我们可以重载内置类型的运算符,如int或float?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文