c++ - Is this standard way to derive from singleton class? -
my base class singleton having protected c'tor. now, can derive class cannot create instance of base class inside functions of derived class. expected behavior per design. know correct c++ standards or compiler specific behavior? (so shouldn't face issues if want port code in future)
class singleton { protected: singleton() {} public: singleton * getinstance() { static singleton* instancecreated = null ; if (!instancecreated) instancecreated = new singleton ; return instancecreated ; } }; class deringlton : public singleton { public: deringlton() { singleton * psing ; // psing = new singlton ; // cannot create object of singlton // (despite class derived singlton) } };
if have make singleton (which should avoid) instance and(!) declaration singleton. use template have 'generic' one, inheritance no good.
Comments
Post a Comment