/*
In the code below, it's unclear whether the call to foo(0) is meant to invoke
the foo(int) or foo(void*) overload. The ambiguity arises because 0 can represent
both a null pointer and an integer.
Solution with nullptr (C++11):
C++11 introduced nullptr, a new keyword that explicitly represents a null pointer
and is not an integer. This removes the ambiguity and makes the code clearer and safer.
*/
#include <iostream>
void foo(int value) {
std::cout << "Integer overload: " << value << std::endl;
}
void foo(void* ptr) {
std::cout << "Pointer overload: " << ptr << std::endl;
}
int main() {
foo(0); // Ambiguous: Is this calling foo(int) or foo(void*)?
return 0;
}