#define 宏和枚举使用相同的名称导致的冲突
Conflict caused by #define macro and enum using same name
我正在尝试将 NVIDIA 的 PhysX 集成到我的 Linux 代码库中。在其某些头文件中,它定义了以下枚举:
physxvisualdebuggersdk/PvdErrorCodes.h
struct PvdErrorType
{
enum Enum
{
Success = 0,
NetworkError,
ArgumentError,
InternalProblem
};
};
physxprofilesdk/PxProfileCompileTimeEventFilter.h:
struct EventPriorities
{
enum Enum
{
None, // the filter setting to kill all events
Coarse,
Medium,
Detail,
Never // the priority to set for an event if it should never fire.
};
};
这会导致以下编译错误:
/usr/local/include/PhysX3/physxvisualdebuggersdk/PvdErrorCodes.h:36:4: error: expected identifier before numeric constant
Success = 0,
^
/usr/local/include/PhysX3/physxvisualdebuggersdk/PvdErrorCodes.h:36:4: error: expected ‘}’ before numeric constant
/usr/local/include/PhysX3/physxvisualdebuggersdk/PvdErrorCodes.h:36:4: error: expected unqualified-id before numeric constant
和
/usr/local/include/PhysX3/physxprofilesdk/PxProfileCompileTimeEventFilter.h:46:4: error: expected identifier before numeric constant
None, // the filter setting to kill all events
^
/usr/local/include/PhysX3/physxprofilesdk/PxProfileCompileTimeEventFilter.h:46:4: error: expected ‘}’ before numeric constant
/usr/local/include/PhysX3/physxprofilesdk/PxProfileCompileTimeEventFilter.h:46:4: error: expected unqualified-id before numeric constant
我已经确定这是因为 X11/X.h #defines"无"和"成功"。我已经确认这是问题所在,因为如果我同时 #undef"无"和"成功",我就不再有错误。但是,这显然不是一件可取的事情。
我的问题是:作为必须同时使用这两个标头的开发人员,我应该采取什么正确的行动方案?我应该将其作为错误报告给 NVIDIA 并等待修复,还是我可以自己做些什么来解决问题(除了 #undef)?
谢谢你的时间!
最明智的做法是分离实现,以便在项目中不要在同一源文件中包含两个冲突的标头。一个文件处理 X,一个文件处理 PhysX,然后您的应用程序将两个实现绑定在一起。
相关文章:
- 不带大括号的枚举形式
- 枚举环境变量的惯用C++14/C++17方法
- 类似枚举的计算常量
- 如何正确实现和访问运算符的各种自定义枚举器
- 错误:从"int"到枚举c++的转换无效
- C++中构造函数中的枚举
- 访问在 C++ 结构中声明的枚举变量
- 枚举类'classname'的多重定义
- 强枚举类型定义:Clang Bug 还是 C++11 标准不确定性?
- typedef 枚举和枚举类有什么区别?
- 在Visual Studio中定义与Typedef枚举发生冲突的原因是什么?
- protobuf-net into .proto 会产生枚举冲突
- 奇怪的枚举名称冲突
- 类名和枚举值之间的冲突:无需命名空间即可解析
- 枚举值与枚举名称冲突
- 基于 SAPI 的应用程序在枚举令牌时引发内存访问冲突
- #define 宏和枚举使用相同的名称导致的冲突
- 全局作用域枚举和命名空间冲突
- 避免预定义的数字常量与c++中的枚举冲突
- 枚举成员与类名冲突