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.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes