c++ access static members using null pointer

TL;DR: Your example is well-defined. Merely dereferencing a null pointer is not invoking UB. There is a lot of debate over this topic, which basically boils down to whether indirection through a null pointer is itself UB. The only questionable thing that happens in your example is the evaluation of the object expression. In particular, … Read more

NULL vs nullptr (Why was it replaced?) [duplicate]

nullptr has type std::nullptr_t. It’s implicitly convertible to any pointer type. Thus, it’ll match std::nullptr_t or pointer types in overload resolution, but not other types such as int. 0 (aka. C’s NULL bridged over into C++) could cause ambiguity in overloaded function resolution, among other things: f(int); f(foo *); (Thanks to Caleth pointing this out … Read more

What exactly is nullptr?

Why nullptr in C++11? What is it? Why is NULL not sufficient? C++ expert Alex Allain says it perfectly here (my emphasis added in bold): …imagine you have the following two function declarations: void func(int n); void func(char *s); func( NULL ); // guess which function gets called? Although it looks like the second function … Read more