What you want is known as a singleton and in a singleton class the constructor is private.
Instead you have a public static member function that returns a dynamically allocated instance
of the class and this instance is a static data member of the class itself.
Code:
class mysingleton
{
public:
static mysingleton* get_instance()
{
if(!instance)
instance = new mysingleton(/*arguments*/);
return instance;
}
private:
mysingleton(/*arguments*/);
static mysingleton *instance;
};
mysingleton* mysingleton::instance=NULL;
Use google to search for singleton (pattern) to learn more.