Search code examples
c++c++11c++-cli

nullptr vs __nullptr


I was just wondering why there are two ways to specify null pointer. I have been going through the link, but did not get clear understanding of its use.

Can someone give a good example of when to use what?


Solution

  • The C++/CLI language already had a nullptr keyword since 2005. That caused a problem when C++11 adopted the nullptr keyword for C++. Now there are two, one for managed code and another for native code. The C++/CLI compiler can compile both. So you have to use __nullptr when you mean the native null pointer, nullptr when you mean the managed null pointer.

    This is only relevant when you compile with /clr in effect. Write C++/CLI code in other words. Just use plain nullptr in C++ code.