What will print the following code?
#include <iostream>
using namespace std;

struct A {
    virtual ~A() = 0;
};
A::~A() { cout << "~A"; }

struct B : A {
    ~B() { cout << "~B"; }
};

int main() {
  A *a = new B;
  delete a;
}
Explanation
In C++ destructors are called recursively for each ancestor class from which this class extends, beginning from the destructor of this class. Since destructor of class A - virtual, then during a deletion, it will call a destructor B, so that C ++ will call a destructor A. Although destructor ~A() is declared as pure virtual, it must be defined.
See the details on http://stackoverflow.com/questions/999340/question-about-pure-virtual-destructor.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести