What will be displayed as a result of the execution of the following code?
#include <iostream>

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

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

int main()
{
  A *a = new B();
  delete a;
  return 0;
}
Explanation
A class destructor is not virtual, so the version of the destructor defined in this class will be called.

Следи за CodeGalaxy

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

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