nullptr

Finding a Pointer to NULL

拜拜、爱过 提交于 2020-01-05 04:33:07
问题 I have int* foo[SIZE] and I want to search it for the first element that points to NULL . But when I do this: std::find(foo, foo + SIZE, NULL) I get the error: error C2446: '==' : no conversion from 'const int' to 'int *' Should I just be using static_cast<int*>(NULL) instead of NULL ? C++11 solves this via nullptr but that's not an option for me in C++03 回答1: tl;dr: Use nullptr , or define your own equivalent. The problem is that NULL is some macro that expands to an integral constant

C++: Compare return value of C function to NULL or nullptr?

牧云@^-^@ 提交于 2020-01-04 04:42:09
问题 I'm coding in C++, and using a C function that returns NULL in case of a failure. What would be the correct think to do, compare its return value to NULL or nullptr? if ((CreateEventEx(myEventHandleHere) == NULL) { ... } or if ((CreateEventEx(myEventHandleHere) == nullptr) { ... } 回答1: The draft C++ standard in appendix C.4 C Standard library which is non-normative says: The macro NULL, defined in any of <clocale>, <cstddef>, <cstdio>, <cstdlib>, <cstring>, <ctime>, or <cwchar>, is an

Why isn't 'nullptr' in the 'std' namespace?

邮差的信 提交于 2020-01-03 06:45:10
问题 It seems that nullptr is declared in the default global namespace. Wouldn't it make sense for it to be in the std namespace? 回答1: nullptr is a C++11 keyword (no different to if , public , true , void , etc.), so namespaces don't apply. 回答2: nullptr is a pointer literal the same way as for example true is a boolean literal. This literal has type std::nullptr_t that is as you see this type is defined in name space std:: The pointer literal is described in section 2.14.7 Pointer literals of the

Where does nullptr_t reside?

时光怂恿深爱的人放手 提交于 2020-01-01 05:30:16
问题 A bit of prehistory. I've been writing a game engine for quite some time. It's divided into several static libraries, like "utils", "rsbin" (resource system), "window", which are then linked into a single executable. It is a crossplatform engine, being compiled for Windows and for Android. Under Windows, I compile it with MinGW. Under Android, with CCTools, which is an interface to native gcc. One of the base classes is utils::RefObject , which represents a concept similar to Windows's

Using Qt Creator C++ 11, nullptr is keyworded?

早过忘川 提交于 2019-12-31 09:48:06
问题 I'm using C++11 using Qt Creator. "warning: identifier 'nullptr' is a keyword in C++11 [-Wc++0x-compat]" "error: 'nullptr' was not declared in this scope" This is on code that works elsewhere, the relevant part being: ... = nullptr; What might be the problem? Is this not already a keyword, isn't it's scope global? 回答1: Open your .pro file from inside QtCreator and add this QMAKE_CXXFLAGS += -std=c++0x 来源: https://stackoverflow.com/questions/16509932/using-qt-creator-c-11-nullptr-is-keyworded

Does the standard behavior for deleters differ between shared_ptr and unique_ptr in the case of null pointers?

此生再无相见时 提交于 2019-12-30 03:45:26
问题 OK, so first some things that might be relevant: I'm using the Clang 3.1 compiler, in C++11 mode, with the standard library set to libc++. I'm trying to familiarize myself with C++11, and in so doing I ran across behavior that seems odd. It may be a quirk of Clang or libc++ but I can't speak C++ standardese and I have no access to other compilers with C++11 support so I can't really check it, and I've searched the internet and Stack Overflow to the best of my ability without finding anything

What header file needs to be included for using nullptr in g++?

早过忘川 提交于 2019-12-29 06:39:08
问题 I am using g++ 4.4.1 and want to use nullptr , but I am not being able to find which header file is required to be included. It does not seem to be keyword either, because my attempt to use it is rejected as error: 'nullptr' was not declared in this scope 回答1: GCC 4.4.1 does not support nullptr . Support for nullptr was added in GCC 4.6.0: http://gcc.gnu.org/gcc-4.6/changes.html Improved experimental support for the upcoming C++0x ISO C++ standard, including support for nullptr (thanks to

What are the advantages of using nullptr?

浪子不回头ぞ 提交于 2019-12-27 10:33:04
问题 This piece of code conceptually does the same thing for the three pointers (safe pointer initialization): int* p1 = nullptr; int* p2 = NULL; int* p3 = 0; And so, what are the advantages of assigning pointers nullptr over assigning them the values NULL or 0 ? 回答1: In that code, there doesn't seem to be an advantage. But consider the following overloaded functions: void f(char const *ptr); void f(int v); f(NULL); //which function will be called? Which function will be called? Of course, the

What are the advantages of using nullptr?

家住魔仙堡 提交于 2019-12-27 10:30:33
问题 This piece of code conceptually does the same thing for the three pointers (safe pointer initialization): int* p1 = nullptr; int* p2 = NULL; int* p3 = 0; And so, what are the advantages of assigning pointers nullptr over assigning them the values NULL or 0 ? 回答1: In that code, there doesn't seem to be an advantage. But consider the following overloaded functions: void f(char const *ptr); void f(int v); f(NULL); //which function will be called? Which function will be called? Of course, the

Could QueryInterface() provide us with nullptr when succeed? [duplicate]

你离开我真会死。 提交于 2019-12-24 11:26:58
问题 This question already has answers here : Handling CoCreateInstance return value (2 answers) Closed 5 years ago . Imagine a situation: CComPtr<IGraphBuilder> pGraph; HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pGraph)); if (SUCCEEDED(hr)) { CComPtr<IMediaControl> pControl; hr = pGraph->QueryInterface(IID_PPV_ARGS(&pControl)); if(SUCCEEDED(hr)) {...} } I wonder, if pControl could ever be nullptr inside last block {...} . The question occurred,