Play and learn 300 000+ tabs online

Saturday, July 10, 2010

singleton class in C++

class CMySingleton
{
public:
  static CMySingleton& Instance()
  {
    static CMySingleton singleton;
    return singleton;
  }

// Other non-static member functions
private:
  CMySingleton() {};                                 // Private constructor
  CMySingleton(const CMySingleton&);                 // Prevent copy-construction
  CMySingleton& operator=(const CMySingleton&);      // Prevent assignment
};

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.