问题描述
我只是想知道为什么有两种方法来指定空指针。我一直在浏览,但没有得到明确的理解
有人可以给出什么时候使用什么的好例子吗? / div>
自2005年以来,C ++ / CLI语言已经有一个 nullptr
关键字。当C ++ 11对C ++采用nullptr关键字时,现在有两个,一个用于托管代码,另一个用于本地代码。 C ++ / CLI编译器可以编译这两者。所以你必须使用__nullptr,当你的意思是本地空指针,nullptr当你的意思是托管的空指针。
这只有当你编译/ clr有效。编写C ++ / CLI代码换句话说。只需在C ++代码中使用纯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?
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.
这篇关于nullptr vs __nullptr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!