在c++中给元素赋地址时出现错误
Getting error while assiging the address of an element in C++
我有两个类,Class A
和class B
。我的代码写在下面。我得到了一个我在最后提到的错误。
class A
{
Private:
B Labels
....
....
};
A::method()
{
Labels.add (label_mark);
....
....
}
A::save()
{
....
....
for (int i = 0; i < Labels.size (); i++)
{
const B& Labels = Labels[i]; //GETTING ERROR HERE
fprintf (file,"%dn",
i + 1,
Labels.timestamp.toString ("%H:%M:%S").c_str (),
}
}
我得到一个错误
error: no match for ‘operator[]’ in ‘Labels[i]’
您在这里隐藏了B
的名称:
const B& Labels = Labels[i];
当您这样做时,RHS上的Labels
是const B&
,而这没有operator[]
。
你需要选择一个不同的名字:
const B& foobar = Labels[i];
相关文章:
- 为什么我在leetcode上收到AddressSanitizer:地址0x602000000058上的堆缓冲区溢出错误
- 地址的奇怪错误
- 为什么我得到以下代码地址清理器:未知地址错误的SEGV
- 运行时错误:引用绑定到类型"int"的未对齐地址0xbebebebebebebec6,这需要 4 个字节对齐 (stl_vector.h)
- 我有一个线程 1:EXC_BAD_ACCESS(代码 = 1,地址 = 0x8)错误.我认为这是由于内存管理不好.我可以
- Assimp 库错误:获取打包成员的地址
- 运行时错误地址清理器:LEETCODE 中的致命信号
- 瓦尔格林德错误 - 地址0x0不是堆叠的 malloc'd 或自由的
- 获取未知分段错误"(地址)在 std::__cxx11::basic_string<char, std::char_traits<char>,..., std::分配器<cha
- 来自简单循环的 OpenAcc 错误:内核执行期间的非法地址
- 带有 NORM 的 ZeroMQ - 地址已在使用 错误被抛出在第二个 .bind() 上 - 为什么?
- 重载新返回错误的地址
- 线程 1:xcode 中出现EXC_BAD_ACCESS(代码 = 1,地址 = 0x0)错误
- C++带有 CMakeList 的地址清理器.txt会导致 asan 错误
- 为什么这段代码给出错误......'a'是指针到字符指针,应该存储's'的地址,因为s是指向数组的第一个元素的指针
- C++ 临时地址不会导致生成错误
- 为什么 LeetCode 给出错误:地址清理器:堆缓冲区溢出
- 分段错误:地址未映射/地址失败:(无)
- 为什么在递增后使用 [] 运算符访问指针数组会返回错误地址的当前内存位置
- 绑定错误:地址已在使用中