STL 映射和指针出现问题
Trouble with STL map and pointers
typedef map<char,string> someMap;
someMap *mapPtr=someClass.getMap();
*(mapPtr)["a"].length();
此代码的最后一行失败。我应该做什么才能使这项工作?
(*mapPtr)['a'].length();
*
运算符的优先级低于[]
因此您必须这样做,但将其放在括号中。 "a"
是字符串文字(字符数组),而您想要'a'
可在此处找到C++运算符优先级的完整列表
[]
的优先级高于*
这可能是您的意图:
(*mapPtr)["a"].length();
相关文章:
- 关于 c++ 函数中指针赋值的简单问题
- 链表指针问题
- C++ 关于指针取消引用的技术问题
- C++中的指针和常量问题不大
- 包含矢量指针的结构的内存释放问题
- 指针问题:从不兼容的类型"int"分配给"int *"
- 将字节数组转换为带有字节序问题的指针
- 关于如何使用指向主窗口的指针的 QT 问题
- 当成员值从指针更改为非指针时,C++常量问题
- 为什么循环会导致指针出现问题?
- 使用指针计算堆栈问题的大 O 表示法
- 构造函数 (C++) 中的 char 指针参数存在问题
- 指向包含对齐 C 结构C++类的 C 指针的对齐问题
- 涉及指针和手动实现的矩阵类的问题
- 从基指针到派生的强制转换问题
- 迭代器的指针操作问题
- 64 位迁移问题:指针更改
- C++模板使用问题指针
- 跳到C++第13章练习问题4-指针
- 用std::pair数组初始化std::map问题(指针错误?)