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.
这篇关于无法评估函数——可能是内联的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法评估函数——可能是内联的


基础教程推荐
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- C++,'if' 表达式中的变量声明 2021-01-01
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- 运算符重载的基本规则和习语是什么? 2022-10-31
- 设计字符串本地化的最佳方法 2022-01-01
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01