简体   繁体   中英

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

I am trying to write a managed C++ (aka C++/CLI) library that links to a third-party native C++ library. The third-party library's header files contain constructor definitions that use the nullptr keyword. My managed project fails to compile because the managed compiler defines nullptr to mean the managed null reference, whereas the third-party uses it to mean the native/un-managed null pointer. How can I work around this problem without modifying the third-party library's header file?

For reference on nullptr vs __nullptr , see: https://msdn.microsoft.com/en-us/library/4ex65770.aspx

C++/CLI supports the same preprocessor directives as C++, right? How about this terrible hack:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM