
int a,b,c; //do stuff. For e.g.,cin >> b >> c; c = a + b; //works c = operator+(a,b); //fails to compile,'operator+' not defined.
这另一方面起作用 –
class Foo{ int x; public: Foo(int x):x(x) {} Foo frIEnd operator+(const Foo& f,const Foo& g) { return Foo(f.x + g.x); }}; Foo l(5),m(10); Foo n = operator+(l,m); //compiles ok! >甚至可以直接调用原始类型的运算符(和其他运算符)(如int)吗?
>如果是,怎么样?
>如果没有,是否有C参考词汇表明这是不可行的?
其次,在重载解析期间,内置运算符确实由它们虚构的函数类似对应物表示,但禁止“内置运算符”的“显式”函数式调用的措辞存在于13.6 / 1中
总结The candIDate operator functions that
represent the built-in operators
defined in clause 5 are specifIEd in
this subclause. These candIDate
functions participate in the operator
overload resolution process as
described in 13.3.1.2 @H_502_26@and are used for no other purpose.
以上是内存溢出为你收集整理的在C中显式调用原始运算符函数全部内容,希望文章能够帮你解决在C中显式调用原始运算符函数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)