C++映射从int到const LexType的无效转换(实际上是由我自己定义的int)



我定义了这样一个映射:

std::map<std::string,LexType> lexname_s = { { "PROGRAM" , PROGRAM}}

还有一个LexType,像这样:

typedef enum 
{
ENDFILE,    ERROR,
PROGRAM,    PROCEDURE,  TYPE,   VAR,        IF,
} LexType;

在Visual Studio代码中,当我触摸它时,它总是显示错误类型

//我补充了我所说的更多细节。线路std::map<std::string,LexType> lexname_s = { { "PROGRAM" , PROGRAM}}显示错误。我似乎无法用这种方式初始化它。我在一个名为centos7的云服务器中,在gcc版本4.8.5 20150623(Red Hat 4.8.5-39((gcc(中编译了它。错误代码显示在下方

from parse.cpp:1:
../utils.h:52:27: error: invalid conversion from ‘int’ to ‘const LexType&’ [-fpermissive]
{"ERROR", ERROR}};
^
In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:64:0,
from /usr/include/c++/4.8.2/bits/stl_tree.h:61,
from /usr/include/c++/4.8.2/map:60,
from ../globals.h:6,
from parse.h:4,
from parse.cpp:1:
/usr/include/c++/4.8.2/bits/stl_pair.h:112:26: error:   initializing argument 2 of ‘constexpr std::pair<_T1, _T2>::pair(const _T1&, const _T2&) [with _T1 = const std::basic_string<char>; _T2 = LexType]’ [-fpermissive]
_GLIBCXX_CONSTEXPR pair(const _T1& __a, const _T2& __b)```

EOF(显示在映射定义中(是stdio.h中定义的保留a宏这就是问题所在。更改名称即可。

相关内容

最新更新