What will be printed out as a result of the following code execution?
#include <iostream>using namespace std;

class A
{
public:
  A(){ cout << "A() "; }
  ~A(){ cout << "~A() "; }
};

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

class C : public B
{
public:
  C(){ cout << "C() "; }
  ~C(){ cout << "~C() "; }
};

int main()
{
  C* p = new C();
  delete p;
}
Explanation
When creating an object of a child class, constructors are called in order from the base to the child. When the object is destroyed, the destructors are called in the opposite order - from the destructor of the child class to the base destructor.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты