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
Зворотній Зв’язок
Продовжуйте вивчати
тести з C++
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести