Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;映射从int到const LexType的无效转换&;(这实际上是我自己定义的int)_C++_C++11_Visual Studio Code - Fatal编程技术网

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

C++ C++;映射从int到const LexType的无效转换&;(这实际上是我自己定义的int),c++,c++11,visual-studio-code,C++,C++11,Visual Studio Code,我定义了这样一个地图: std::map<std::string,LexType> lexname_s = { { "PROGRAM" , PROGRAM}} typedef enum { ENDFILE, ERROR, PROGRAM, PROCEDURE, TYPE, VAR, IF, } LexType; 在VisualStudio代码中,当我触摸它时,它总是显示错误类型 // 我为我所说的补充了更多细节

我定义了这样一个地图:

std::map<std::string,LexType> lexname_s = { { "PROGRAM" , PROGRAM}}
typedef enum 
{
    ENDFILE,    ERROR,
    PROGRAM,    PROCEDURE,  TYPE,   VAR,        IF,
} LexType;
在VisualStudio代码中,当我触摸它时,它总是显示错误类型

// 我为我所说的补充了更多细节。 线路
std::map 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)```
来自parse.cpp的
:1:
../utils.h:52:27:错误:从“int”到“const LexType&”的转换无效[-fppermissive]
{“错误”,错误};
^
在/usr/include/c++/4.8.2/bits/stl_algobase.h:64:0中包含的文件中,
从/usr/include/c++/4.8.2/bits/stl_tree.h:61,
从/usr/include/c++/4.8.2/map:60,
来自../globals.h:6,
从parse.h:4开始,
来自parse.cpp:1:
/usr/include/c++/4.8.2/bits/stl_pair.h:112:26:错误:初始化'constexpr std::pair::pair(const_T1&,const_T2&)[带_T1=const std::basic_string;_T2=LexType]'的参数2[-fppermissive]
_GLIBCXX_CONSTEXPR对(常数T1和a,常数T2和b)```
EOF(显示在映射定义中)是stdio.h中定义的保留a宏 这就是问题所在。
更改名称就可以了。

LexType
看起来根本不像
int
。到底是什么?一个
struct
,或者一个
enum
?当我触摸它时,你所说的
到底是什么意思?仅当您更改其定义或使用它时,它才会显示错误。另外,使用基于Visual Studio 16.9的MSVC,您的代码似乎可以很好地编译。请注意,VS代码是一个文本编辑器,与Visual Studio本身不同。它可能使用msvc、mingw、WSL连接、容器或云实例来编译代码。1。实际上是一个枚举。在任何地方都不会有名为
ERROR
的宏,对吗?