default keyword virtual destructor
c++, c++11
Solution
Is virtual ~Base() = default; legal
Yes. it is.
If you want to have a pure virtual destructor, you can do the following:
class Base
{
public;
virtual ~Base() = 0;
};
and provide implementation:
Base::~Base() = default; // or any other implementation
So `Base` is virtual pure. It can be done with pre C++11 (change `= default;` by `{}`).
Problem
I have been using more and more C++11 and I have come across something that I couldn't find anywhere. When we delete derived class from base pointer, we need to have virtual destructors; but sometimes the parent destructor needs to be "pure", which is not really possible with C++. So, my question is can default be used for virtual destructors? I have already tried it and it works but I don't know if its safe as there is no information about it anywhere in the internet. EDIT: To clarify the problem, I am talking about using `virtual ~Class() = default;`