class B derived from an abstract base class A, and how can i use singleton in class B?

  abc, c++, singleton

below is the demo code:

class A {
public:
    A(){}    
    virtual void method()=0;
    //....
    virtual ~A(){};
}

class B : public A{
    static A * ptr;
    //....
public:
    //....
    static A* GetInstance() {
        if (ptr == nullptr)
            ptr = new B();  // error, currently B is an abstract class, it has not been constructed
        return ptr;
    }
    //.....
}

class B derived from an abstract base class A, and how can i use singleton in class B?

Source: Windows Questions C++

LEAVE A COMMENT