A pure virtual - or abstract - destructor needs an implementation in C++. For example this program does not link because of an "undefined reference to A::~A".
class A {
public:
virtual ~A() =0;
};
class B : public A { };
int main()
{
B b;
}
This contradicts the definition of abstract functions. As on the one hand there is no other way to make a class whithout methods abstract and on the other hand a destructor must always be available there is no way out.
Seen on "Scott Meyers, Effective C++, Item 14".
No comments:
Post a Comment