cpp_nullptr - 8BitsCoding/RobotMentor GitHub Wiki

cpp_cpp11_nullptr

nullptr

NULL에는 아래와 같은 문제가 있었다.

// class.h
float GetScores(const char* name);
float GetScores(int id);

// main
Class* myClass = new Class("COMP3100");

int score = myClass->GetScore(NULL);    // 어떤함수가 호출되나?

NULL의 정의를 보면 명확하다.

#define NULL 0
// 0으로 디파인
typedef decltype(nullpty) nullptr_t;

int number = NULL;              // OK
int* ptr = NULL;                // OK

int anotherNumber = nullprt;    // Error
int* anotherPtr = nullptr;      // OK