加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 是否在内部函数中被调用?

发布时间:2020-12-16 03:23:54 所属栏目:百科 来源:网络整理
导读:是否在一个typeid中调用函数?考虑下面的代码 #include iostream#include typeinfousing namespace std;int mul10(int s){ static int count = 1; cout "Evaluating call " count endl; count++; s *= 10; return(s);}int main(){ int i = 5; cout typeid(mu
是否在一个typeid中调用函数?考虑下面的代码
#include <iostream>
#include <typeinfo>
using namespace std;

int mul10(int &s)
{
    static int count = 1;
    cout << "Evaluating call " << count << endl;
    count++;
    s *= 10;
    return(s);
}

int main()
{
    int i = 5;
    cout << typeid(mul10(i)).name() << endl;
    cout << i << endl;
    return(0);
}

所以这里的输出是

int
5

很明显,我的价值并没有改变,而且mul10的功能并没有被实际调用.这是如何评估typeid参数的?

解决方法

typeid的操作数只有在多态类类型的glvalue时才被评估.由于mul10的返回类型(即int)不是多态类类型,所以操作数不被评估,这意味着mul10不被调用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读