c - VS2015 中 C 代码中的无作用域枚举

标签 c c++11 visual-c++ enums visual-studio-2015

我正在尝试使用 VS 2015 和 Windows 10 SDK 编译适用于 Python 的 psutil 模块。编译失败并出现以下错误:

c:\users\builder\documents\code\psutil\psutil\arch\windows\ntextapi.h(212): error C2365: 'ProcessBreakOnTermination': redefinition; previous definition was 'enumerator'
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\um\winternl.h(308): note: see declaration of 'ProcessBreakOnTermination'
c:\users\builder\documents\code\psutil\psutil\arch\windows\ntextapi.h(212): error C2086: '_PROCESSINFOCLASS2 ProcessBreakOnTermination': redefinition
c:\users\builder\documents\code\psutil\psutil\arch\windows\ntextapi.h(212): note: see declaration of 'ProcessBreakOnTermination'

进一步调查显示 ProcessBreakOnTermination 是 Winternl.h 中枚举 (PROCESSINFOCLASS) 的一部分。

我相信这与 C++11 强制作用域枚举有关:https://msdn.microsoft.com/en-us/library/vstudio/2dzy4k6e(v=vs.110).aspx

但是,我不知道如何解决这个问题。如果我尝试添加 MS 网站上详细说明的类或结构位,则会出现编译器错误,因为它被编译为 C 代码。为什么 C++11 规则应该应用于这里的 C 代码?

最佳答案

我想出的解决方案是将有问题的双重定义符号包装在 #if 中。

(start of enum)
(last good entry)
#if _MSC_VER < 1900
(offending enum entry)
#endif
(next entry) = (last_good_entry)+2

欢迎任何更好的解决方案!

关于c - VS2015 中 C 代码中的无作用域枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32785133/

相关文章:

c - 参数传递问题

c - libgcrypt-config --libs : no such file or directory

c++ - 在 Makefile 中处理多个扩展的优雅方法

c++ - 部分类模板特化 c++11

c++ - Visual Studio 下的 std::nan/std::nanf 有什么问题?

c++ 这里正确的语法是什么?

c# - 从 WM_COPYDATA 消息编码结构

visual-c++ - 数字电视设备选择需要哪些用户输入?

c++ - 在 C++ 中使用异常基类导致应用程序崩溃

c++ - istream::seekg 和 ios_base::end 可靠吗?