What is the purpose of adding a definition for a pure virtual destructor?

Inspired by: C ++ - why should we define a pure virtual destructor outside the class definition?

What does the following code do?

class Object
{
    public:
    virtual ~Object() = 0;
};

Object::~Object() { /*...*/ }

I thought the point of a pure virtual function was to force subclasses to implement this particular function. If so, then why bother with implementing the same function in a virtual base class?

+3
source share
2 answers

This code does not allow you to instantiate an object and at the same time allows you to create subclasses.

, . , . - , , Foo:theFunc().

+10

"" - . . , ( ) - .

, :

  • , , , , .
  • , ( , ) .
+2

All Articles