#include using namespace std; class CxFactory; class Cx { friend CxFactory; public: void Show(); void Increment(); private: Cx(); // data members int m_x; }; class CxFactory { public: static Cx& Instance(); private: CxFactory(); static Cx m_Cx; }; Cx CxFactory::m_Cx; Cx::Cx() { m_x = 0; } void Cx::Show() { cout << "Cx m_x = " << m_x << endl; } void Cx::Increment() { m_x++; } Cx& CxFactory::Instance() { return m_Cx; } CxFactory::CxFactory(){} void main() { Cx& x1 = CxFactory::Instance(); x1.Show(); x1.Increment(); x1.Show(); Cx& x2 = CxFactory::Instance(); x2.Increment(); x2.Show(); x1.Show(); }