NULL vs nullptr (Why was it replaced?)

Riptyde4 picture Riptyde4 · Dec 11, 2013 · Viewed 171.5k times · Source

I know that in C++ 0x or NULL was replaced by nullptr in pointer-based applications. I'm just curious of the exact reason why they made this replacement?

In what scenario is using nullptr over NULL beneficial when dealing with pointers?

Answer

Joe Z picture Joe Z · Dec 11, 2013

nullptr is always a pointer type. 0 (aka. C's NULL bridged over into C++) could cause ambiguity in overloaded function resolution, among other things:

f(int);
f(foo *);