对函数应用增量运算符 [英] Apply increment operator to a function

查看:134
本文介绍了对函数应用增量运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有这样的情况,这将是有效的C ++代码?

Is there a case where this would be valid C++ code?

int main()
{
    int k = 0;
    ++f(k);
}


推荐答案

$ c> f 返回引用。

Yes, if f returns a reference.

int main()
{
    int k = 0;
    ++f(k);
}

int & f(int & k) {
    return k;
}

编辑:

如注释中所指出的,还有另一种可能性:如果 f ++ f(k) >返回一个类类型,它具有 ++运算符(void)作为成员函数重载。

As pointed out in the comments, there is another possibility: you can call ++f(k), if f returns a class type and it has the ++operator(void) overloaded as a member function.

这篇关于对函数应用增量运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆