Netbeans在使用c++std::map::operator[]时遇到一些问题
Netbeans having some trouble with c++ std::map::operator[]
我正在使用Netbeans IDE 8.0,但遇到了一些问题。
下面是一段解释问题的代码:
typedef struct Context {
bool finished;
bool reliable;
bool running;
bool firstAckReceived;
map<uint32_t, uint32_t>* missingChunks;
} Context;
map<uint32_t, Context*>* contexts;
...
this->contexts->operator[]((uint32_t) ctrl.getSource())->running = true;
当使用建议(CTRL+Space)时,运算符[]返回Context&正如预期的那样,但之后不能给我任何建议。Netbeans并不认为它是一个可以被取消引用以获取Context字段的Context。
编译可以此外,"跑步"被强调为一个一直困扰着我的错误。这种情况经常发生吗?
另外,我认为我应该能够使用如下语法访问元素,但g++抱怨。。。
this->contexts[(uint32_t) ctrl.getSource()]->running = true;
有什么想法吗?
我想你有
this->contexts->operator[]((uint32_t) ctrl.getSource())->running = true;
// ^------------- notice this
而不是
this->contexts.operator[]((uint32_t) ctrl.getSource())->running = true;
// ^------------- notice this
回想一下,我们将->
用于指针,将.
用于非指针。
以下
this->contexts[(uint32_t) ctrl.getSource()]->running = true;
相当于第二个版本。你要么需要取消引用指针,要么,我喜欢的方式,考虑一下为什么你有这么多原始指针
我建议你换
map<uint32_t, Context*>* contexts;
至
map<uint32_t, Context*> contexts;
然后您应该考虑谁拥有映射中的原始Context
指针。
相关文章:
- 编译包含字符串的代码时遇到问题
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- 从其他类访问类时遇到问题
- 使用静态成员声明类时遇到问题
- C++ 填充数组时遇到问题
- 在将字符串放入字符串向量时遇到问题?
- 余数除法和不允许除以零 (c++) 时遇到问题
- 我在C++中使用 getline() 函数时遇到问题
- C++线程安全:如果只有一个线程可以写入非原子变量,但多个线程从中读取. 会遇到问题吗?
- 在我的四叉树实现中遇到问题
- 在 c++ 中循环遍历数组时遇到问题
- 使用 MinGW 在 Windows 上构建 GLEW 时遇到问题
- 编译 Cilk Plus 程序时遇到问题
- 存储另一个函数返回的布尔数组时遇到问题
- 我在 OpenGL 中显示图像时遇到问题
- 我在解决此错误时遇到问题.我正在努力在主函数中传递数组
- 在 for 循环中更新两个变量时遇到问题C++
- 为什么我的程序在打开网络设备时遇到问题
- 在 Tensorflow C++ 中使用 FIFOQueue 时遇到问题
- 为什么我在虚幻引擎中的多态性和接口方面遇到问题?