如何#include third-party 本机 C++ header 在 C++/CLI 项目中使用 nullptr

how to #include a third-party native C++ header that uses nullptr in a C++/CLI project

我正在尝试编写链接到 third-party 本机 C++ 库的托管 C++(也称为 C++/CLI)库。 third-party 库的 header 文件包含使用 nullptr 关键字的构造函数定义。我的托管项目无法编译,因为托管编译器将 nullptr 定义为托管空引用,而 third-party 使用它来表示 native/un-managed 空指针。如何在不修改 third-party 库的 header 文件的情况下解决此问题?

有关 nullptr__nullptr 的参考,请参阅:https://msdn.microsoft.com/en-us/library/4ex65770.aspx

C++/CLI 支持与 C++ 相同的预处理器指令,对吗?这个可怕的黑客怎么样:

#define _ALLOW_KEYWORD_MACROS
#define nullptr __nullptr
#include "header.h"
#undef nullptr