In a medium size code I have a base class like this
class Base {
public:
virtual ~Base() = 0; //This is the important point
};
In a derivate class I have something like this
class Derivate : public Base {
public:
~Derivate();
};
An implementation of the virtual constructor is provided (it basically does some deallocation on the base class) the derivate class extends such behaviour to the derivate class. Since the base class is abstract I cannot instantiate anything.
I have a wrapper class like this
class Wrapper {
public:
~Wrapper();
private:
Base *stuff;
}
Now I could have several derivates classes of the base one, so basically the purpose would be to let the user have the freedom of chose what to put in stuff
The destructor of Wrapper
is implemented as
Wrapper::~Wrapper() {
stuff->~Base();
}
(My actual code follows such pattern). However when the destructor of wrapper is called an error is returned when I debug using gdb
, where basically is stated that ~Base()
Is a pure virtual method, which is true, however I thought that because is virtual anyway the actual constructor of the derivate class would have been called instead.
Is my understanding wrong? What Am I missing? Shall I decler the destructor of Base
just as virtual and not pure virtual?
Note : Please keep in mind that the code I posted is a just some scratch.
Thank you.
stuff
object. Is that right? If yes I still don't understand why explicitly calling the destructor would be wrong. – user8469759 Nov 14 '16 at 13:14