无法评估功能 - 可能内联 [英] Cannot evaluate function -- may be inlined

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

问题描述

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

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

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



**无法评估函数 - 可能内联**



如何才能从内联函数打印值?

解决方案

你得到这个错误是因为你把func的定义放在类体中,因此,首先,编译器内嵌了这个函数 - 这意味着,编译将用它的定义替换此函数调用的所有外观,并且该函数的定义将不在可执行文件中。其次,你并没有真的在你的程序中调用这个函数,所以实际上,这个函数在你的最终可执行文件中是不存在的!



解决这个问题:


  1. 您可以将func的定义放在课程体外。


I wrote a function similar to this:

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

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

**Cannot evaluate function -- may be inlined**

How to can I print values from an inlined function?

解决方案

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!

To solve that:

  1. You can put the definition of func outside the class body.
  2. Call func in your program anywhere.

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

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