Which class destructor will be called first, when following code go out of scope? [code] class A{ }; class B{ }; class C: public B{

Which class destructor will be called first, when following code go out of scope?
Code:
class A{  };
class B{  };
class C: public B{  };
A a;
B b;
C c;
A. ~A()
B. ~B()
C. ~C()
D. ~B() and ~C()
 
Answer: c
Explanation: The constructor that would have created at last, its destructor will be called first when the code goes out of scope. This will help the program to manage the resources more efficiently.
 

Tìm kiếm

Back
Top