c++ - How to use singleton and pure virtual function together? -


class base{         static base* m_selfinstance;     public:         static base* getinstance();         virtual void abc() = 0;     };     class der:public base{     public:         void abc(){cout << "derived...\n";}     };     base* base::m_selfinstance = null;     base* base::getinstance()         {             if(m_selfinstance == null)             {     /*throws error here , it's natural, because it's violates c++ standard*/                     m_selfinstance = new base();                     }                 return m_selfinstance;             }             int main()             {                 base *b = base::getinstance();                 //b->abc();             system("pause");             return 0;             } 

in case how deal singleton , pure virtual function together. if i'll make m_selfinstance = new der(); things works fine. real problem occur if there more derived classes der_1 , der_2 @ time istance m_selfinstance = new der(); instead of new der_1() or new der_2() . please guide me how go ahead this.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -