gdb Could not find operator[](gdb 找不到运算符 [])
问题描述
double var1, var2;
std::vector<double *> x;
var1 = 1;
var2 = 2;
x.push_back(&var1);
x.push_back(&var2);
当我在 gdb 中调试此代码并尝试 print x[0] 或 *x[0] 时,我得到:
When I debug this code in gdb and try print x[0] or *x[0] I get:
找不到运算符[].
现在,如果我在 push_back 之后包含这一行:
Now if I include this line after the push_back:
x[0] = &var1;
我可以访问 gdb 中的任何特定元素.front()、at() 等其他成员也会发生同样的情况.我的理解是编译器/链接器仅包含源中存在的成员函数代码,这些是我可以在 gdb 中使用的.有没有办法包含 std::vector 的每个成员函数,以便我可以在 gdb 中访问它们?
I can access any specific elements in gdb. The same thing happens with other members such as front(), at(), etc. My understanding is that the compiler/linker includes only the member functions present in the source code and those are the ones I can use in gdb. Is there a way to include every member function of std::vector so I can access them in gdb?
推荐答案
我的理解是编译器/链接器只包括源代码中存在的成员函数,这些是我可以在 gdb 中使用的.
My understanding is that the compiler/linker includes only the member functions present in the source code and those are the ones I can use in gdb.
您的理解不正确/不完整.
Your understanding is incorrect / incomplete.
std::vector 是一个模板类.如果没有显式实例化,编译器需要仅实例化调用的方法(通常是源中存在的方法的子集).
std::vector is a template class. Without explicit instantiation, the compiler is required to instantiate only the methods called (usually a subset of methods present in the source).
有没有办法包含 std::vector 的每个成员函数,以便我可以在 gdb 中访问它们?
Is there a way to include every member function of std::vector so I can access them in gdb?
对于给定类型 T,您应该能够通过请求显式实例化该 T 的 整个 向量,例如:
For a given type T, you should be able to explicitly instantiate entire vector for that T, by requesting it, e.g.:
template class std::vector<double>;
这篇关于gdb 找不到运算符 []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:gdb 找不到运算符 []
基础教程推荐
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 这个宏可以转换成函数吗? 2022-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 我有静态或动态 boost 库吗? 2021-01-01
