#include <iostream>
class Singleton {
private:
static Singleton* s_instance;
public:
static Singleton& Get() {
return *s_instance;
}
void Hello() {
std::cout << "Hey Bro" << std::endl;
}
};
Singleton* Singleton::s_instance = nullptr;
int main() {
Singleton::Get().Hello();
return 0;
}
And it prints the output from the member function Hello(). How can a nullptr be dereferenced in the static member function Get()
P.S: This code snippet was taken from the Cherno C++ series on YouTube.