错误 C2062:引用 std::map 时键入意外
Error C2062: type unexpected when referencing std::map
#include <string>
#include <map>
namespace myNamespace
{
struct MyStruct
{
static std::map<int, std::string> idNameMap;
// some other static properties
};
class MyClass
{
private:
void myMethod() {
std::map<int, std::string>& myMap = MyStruct::idNameMap; // C2062: type 'int' unexpected
for (auto& it : myMap)
{
// do some stuff with map values
}
}
};
}
我正在尝试引用MyStruct
中的静态映射属性,但它产生了此错误。我不确定是否需要更多上下文,但如果需要,请告诉我。
让我们再试一次...
您可能在代码中的某个地方有一个错误终止的定义,就在 int 变量之前,该定义未包含在您的问题中。
即,通过对已发布代码的添加,您将获得完全相同的编译器错误:
#include <string>
#include <map>
double x = 42.0, // ERROR! incorrectly terminated before an 'int' variable
int a = 0;
namespace myNamespace
{
...
相关文章:
- 在C++中对T*类型执行std::move的意外行为
- 概念解析为使用 std::make_signed_t 时意外的函数模板
- std::shared_ptr vs std::make_shared:意外的缓存未命中和分支预测
- 在调用 std::bind 的产品后意外调用析构函数
- 意外的模板与VC++中的std::void_t匹配
- std::cout 的意外行为
- C++ std::valarray 成员变量意外更改
- 使用相同的函数时意外收到"std::out_of_range"错误
- std::regex_error语言 - 意外的转义字符
- 如何避免 std::abs 的意外结果?
- C++ std::find() 寻址返回向量的类函数时的意外行为
- 基于范围的 std::move 调用意外复制构造函数
- 与 std::experimental::d irectory_iterator 的意外混叠
- 从函数的返回值将元素C++存储到 std::vector 中时出现意外结果
- 这个std :: cout最终会打印垃圾还是意外的东西
- C++使用 std::get_time 解析 YYMMDD ISO 8601 日期字符串会得到意外结果
- 将 std::sort 与指向整数变量的指针一起使用会产生意外的输出
- STD :: Istream意外结束
- 为什么在std :: string上尺寸运算符会产生意外结果
- 错误 C2062:引用 std::map 时键入意外