Possible Duplicate:
“Backporting” nullptr to C++-pre-C++0x programs
How to define nullptr for supporting both C++03 and C++11?
Does below code is compiled with both C++03 and C++11 compiles without change the meaning of nullptr in C++11 compiler?
#include <cstddef>
#if !defined(nullptr)
#define nullptr NULL
#endif
In C++11,
nullptris of typenullptr_t. One of its big advantages compared toNULL(or to0would say Bjarne since he does not like macros) is that between these two functions:foo(nullptr)will call thechar*overload butfoo(NULL)will call theintoverload. So your solution may work in most of the cases, but you may have errors with functions overload.