This rule is Obsolete | |
Synopsis: | Use nullptr instead of 0 or NULL for pointers |
Language: | C++ |
Severity Level: | 6 |
Category: | Object Allocation |
Description: |
The keyword "nullptr" denotes the null pointer. It has been introduced in C++11 to replace all other, less elegant ways to denote the null pointer such as NULL and 0. nullptr is preferred to NULL and 0 because it improves type safety and avoids ambiguous situations. An ambigious situation for the old null pointer type is shown below: void f(char const *ptr); void f(int v); f(NULL); //which function will be called? Wrong examples: ptr = 0; if (ptr == NULL) { ... } Right examples: ptr = nullptr; if (ptr == nullptr) { ... } |