How the order of constructors and destructors invocations will influence the result and what will be printed out in console?
#include <iostream>

using namespace std;

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

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

int main(void) {
  B b;
  A &a = b;
  a();
  b();
  return 0;
}

Follow CodeGalaxy

Mobile Beta

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