Cannot evaluate function -- may be inlined(无法评估函数——可能是内联的)
问题描述
我写了一个类似这样的函数:
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!
解决这个问题:
- 您可以将 func 的定义放在类体之外.
- 在您的程序中的任何地方调用 func.
这篇关于无法评估函数——可能是内联的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法评估函数——可能是内联的
基础教程推荐
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
