I know the cases where pure virtual destructors are needed. I also know that If we don't provide an implementation for them it will give me a linker error. What I don't understand is why this should be the case in a code fragment as shown below:
int main()
{
Base * p = new Derived;
}
Here there is no delete, so no call to destructor and so no need for its implementation(assuming it is supposed to behave like other normal functions which are declared but not defined, linker complains only when we call them)...or am I missing something?
I need to understand why this should be a special case?
Edit: based on comments from BoBTFish
Here are my Base and Derived classes
class Base
{
public:
Base(){}
virtual ~Base() = 0;
};
class Derived : public Base
{
};
Base
andDerived
, but I guess what is happening is the compiler is generating the destructor forDerived
, which will try to call the destructor forBase
, which does not exist. – UnslingBase::~Base()
function is going to be implemented. As forDerived::~Derived()
, since you did not defined it, it's automatically generated (equivalent to~Derived() = default;
). – Orestes