Question discussion

What is the output of the following C++ code, given that Base's destructor is NOT declared virtual? class Base { public: Base() { cout

551Medium DSSSB TGT Computer Science 0 replies 1 views
0
What is the output of the following C++ code, given that Base's destructor is NOT declared virtual? class Base { public: Base() { cout << "Base "; } ~Base() { cout << "~Base "; } }; class Derived : public Base { public: Derived() { cout << "Derived "; } ~Derived() { cout << "~Derived "; } }; int main() { Base *b = new Derived(); delete b; return 0; }
  • ABase Derived ~Base ~Derived
  • BBase Derived ~Derived ~Base
  • CBase Derived ~Base
  • DCompilation error
Correct answer: C

Discussion 0

Nobody has replied yet. Start the discussion!