Search code examples
c++nullc++11nullptr

Perfectly emulate nullptr


I got tired of waiting for compiler support of nullptr (gcc 4.6 does but it's so new few distributions support it).

So as a stop gap until nullptr is fully supported I decided to emulate it. There are two examples of emulation: one from here, and one from wikibooks.

Of note, neither implementation mentions an operator ==. However, without one, the following code will not compile.

int* ptr = nullptr;
assert( ptr == nullptr ); // error here: missing operator ==

Is this operator == error a compiler bug?
Is operator == (and !=, <, <=, etc) needed to more perfectly emulate nullptr?
What else is different between an emulated nullptr and the real deal?


Solution

  • You compiled it with C++0x compiler that failed for unknown reason. It compiles fine in C++03.