Before C++11, the NULL identifier was meant to be used for pointers. In this recipe, we'll see why this was a problem and how C++11 solved it.
Learning how nullptr works
How to do it...
To understand why nullptr is important, let's look at the problem with NULL:
- Let's write the following code:
bool speedUp (int speed);
bool speedUp (char* speed);
int main()
{
bool ok = speedUp (NULL);
}
- Now, let's rewrite the preceding code using nullptr:
bool speedUp (int speed);
bool speedUp (char* speed);
int main()
{
bool ok = speedUp (nullptr);
}