#define宏和枚举使用相同名称引起的冲突

时间:2014-12-30 17:02:18

标签: c++ enums x11 physx

我正在尝试将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' None'并且'成功'我已经确认这是问题所在,如果我#undef都没有'没有'和'成功',我不再有错误。但是,这显然不是一件令人满意的事情。

我的问题是:作为必须同时使用这两个标题的开发人员,我采取的正确行动方案是什么?我应该把它作为一个bug报告给NVIDIA并等待修复,还是我可以自己解决这个问题(#undef除外)?

谢谢你的时间!

1 个答案:

答案 0 :(得分:1)

最严格的行动方案是以这样一种方式分离实施,即在您的项目中,您不必在同一源文件中包含两个冲突的标题。一个文件处理X,一个处理PhysX,然后您的应用程序将两个实现联系在一起。