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