gdb找不到运算符[] [英] gdb Could not find operator[]
问题描述
double var1, var2;
std::vector<double *> x;
var1 = 1;
var2 = 2;
x.push_back(&var1);
x.push_back(&var2);
当我在gdb中调试这个代码并尝试打印x [0]或* x [0] get:找不到operator []。
现在如果我在push_back之后包含这行:
When I debug this code in gdb and try print x[0] or *x[0] I get: Could not find operator[]. 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. 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找不到运算符[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!