gdb 找不到运算符 []

gdb Could not find operator[](gdb 找不到运算符 [])
本文介绍了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 找不到运算符 []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)