Trước C++11, NULL thường là macro #define NULL 0 — kiểu int, gây nhập nhằng khi overloading.
cpp
void foo(int x) { std::cout << "int"; }
void foo(char* p) { std::cout << "pointer"; }
foo(NULL); // trước C++11: "int" — sai ý định!
foo(nullptr); // C++11: "pointer" — đúngnullptr là literal kiểu std::nullptr_t, chuyển đổi ngầm về bất kỳ pointer type nào nhưng không về int.
Quy tắc hiện đại: luôn dùng nullptr thay NULL hoặc 0 trong C++ — rõ ràng về ý định và type-safe.
Before C++11, NULL was typically #define NULL 0 — an integer type, causing overload ambiguity.
cpp
void foo(int x) { std::cout << "int"; }
void foo(char* p) { std::cout << "pointer"; }
foo(NULL); // pre-C++11: "int" — wrong intent!
foo(nullptr); // C++11: "pointer" — correctnullptr is a literal of type std::nullptr_t, implicitly convertible to any pointer type but not to int.
Modern rule: always use nullptr instead of NULL or 0 in C++ — clearer intent and type-safe.