// Ivan Novick // Dec-23, 2007 // Meyers singleton pattern #include class Singleton { public: static Singleton& Instance() { static Singleton s; return s; } void hello() { std::cout << "Hello World address is " << this << std::endl; } protected: // prevent users from calling any of these Singleton() {} Singleton(Singleton&); Singleton& operator=(const Singleton&); }; int main(int argc, char** argv) { // should be 3 references to same object Singleton& s1 = Singleton::Instance(); Singleton& s2 = Singleton::Instance(); Singleton& s3 = Singleton::Instance(); // should print out the same memory address 3 times s1.hello(); s2.hello(); s3.hello(); return 0; }