无法评估函数——可能是内联的 [英] Cannot evaluate function -- may be inlined

查看:28
本文介绍了无法评估函数——可能是内联的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个类似这样的函数:

I wrote a function similar to this:

class abc {
    private :
    int m_var ;
    public :
    int func() { return m_var ; }
};

当我尝试使用 gdb 中的 abc 对象指针打印 func() 时,它给出了错误:

When I try to print the func() using an abc object pointer in gdb, it is giving the error:

**无法评估函数——可能被内联**

如何打印内联函数的值?

How to can I print values from an inlined function?

推荐答案

出现这个错误是因为你把func的定义放在类体中,而且它足够小,所以,首先编译器内联了这个函数----也就是说,编译将用它的定义替换这个函数调用的所有外观,并且这个函数的定义不会出现在可执行文件中.其次,你并没有真正在你的程序中调用那个函数,所以事实上,这个函数永远不会存在于你的最终可执行文件中!

You got this error because you put func's definition in the class body and it's small enough, so, first, the compiler inlined this function ---- that means, the compile will substitute all the appearance of this function's call with its definition, and no definition of this function will be in the executable file. And, second, you didn't really call that function in your program, so in fact, this function never exist in your final executable file!

解决这个问题:

  1. 您可以将 func 的定义放在类体之外.
  2. 在您的程序中的任何地方调用 func.

这篇关于无法评估函数——可能是内联的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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