Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nullptr vs __nullptr

Tags:

c++

c++11

c++-cli

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?

like image 477
AksharRoop Avatar asked Nov 02 '11 09:11

AksharRoop


1 Answers

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.

like image 96
Hans Passant Avatar answered Sep 23 '22 20:09

Hans Passant