问题描述
我写了一个类似这样的函数: class abc {
private:
int m_var ;
public:
int func(){return m_var; }
};
当我尝试打印 func()
在 gdb
中使用 abc
对象指针,它会给出错误:
**无法评估函数 - 可能内联**
如何才能从内联函数打印值?
解决这个问题:
- 您可以将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:
- You can put the definition of func outside the class body.
- Call func in your program anywhere.
这篇关于无法评估功能 - 可能内联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!