I have been playing c ++ 11 for the last two days. One of them is the New Keyword nullptr. Here we will discuss the value of nullptr, its application scenarios, and how to simulate nullptr when c ++ 11 is not supported. 1. Why is there nullptr? When we assign an initial value to a pointer, we generally Write FILE * fp = NULL. Here is a NULL definition, which is generally defined as follows: [cpp] # ifdef _ cplusplus # define NULL 0 # else # define NULL (void *) 0) # endif in the C language environment, due to the absence of function overloading and other issues, defining NULL as a void * pointer can solve all problems perfectly. But in the c ++ environment, the situation becomes complicated. First, we cannot write such code FILE * fp = (void *) 0; it is illegal to assign void * directly to a pointer. The Compiler reports an error. We can only write code [cpp] FILE * fp = (FILE *) 0 in this way; // or FILE * fp = 0; so in c ++, NULL is directly defined as an integer 0. In most cases, this does not cause any problems, but in case of heavy loads or template derivation, the compiler will not be able to give the correct results. For example, in the following scenario: [cpp] void call_back_process (CCObject * target, void * data); bind (call_back_process, target, NULL); // The error function type is void *, however, we are bound to an Application Scenario of integer 0 2 and nullptr: if our compiler supports nullptr, we should directly use nullptr to replace NULL macro definitions. They are completely equivalent during normal use. 3. Simulate nullptr implementation: Some compilers do not support nullptr, A New Keyword of c ++ 11. We can also simulate a nullptr [cpp] www.2cto. comconst class nullptr_t_t {public: template <class T> operator T * () const {return 0;} template <class C, class T> operator t c ::*() const {return 0;} private: void operator & () const;} nullptr_t = {};# undef NULL # define NULL nullptr_t