Common wisdom is that if you can make a class abstract by having a pure virtual destructor.
To quote Herb Sutter:
All base classes should have a virtual destructor (see your favourite C++ book for the reasons). If the class should be abstract (you want to prevent instantiating it) but it doesn't happen to have any other pure virtual functions, a common technique to make the destructor pure virtual:
However the following code compiles for me with GCC and VC:
#include <iostream>
struct base {
virtual ~base() = 0;
};
base::~base() { std::cout << "base destructor\n"; }
struct derived : base { };
int main() {
derived d;
}
Has something changed in C++11 that I'm not aware of?
BTW the motivation to this question is an answer I gave five years ago and was suddenly challenged by a commenter.