C++ Programming - Constructors and Destructors - Discussion
Discussion Forum : Constructors and Destructors - Programs (Q.No. 13)
13.
What will be the output of the following program?
#include<iostream.h>
class BixBase
{
public:
BixBase()
{
cout<< "Base OK. ";
}
~BixBase()
{
cout<< "Base DEL. ";
}
};
class BixDerived: public BixBase
{
public:
BixDerived()
{
cout<< "Derived OK. ";
}
~BixDerived()
{
cout<< "Derived DEL. ";
}
};
int main()
{
BixBase *basePtr = new BixDerived();
delete basePtr;
return 0;
}
Discussion:
3 comments Page 1 of 1.
Nathas said:
6 years ago
Thank you @Maytas.
Maytas said:
1 decade ago
If destructor in Base class is NON-VIRTUAL then compiler does NOT call derived class destructor, calls ONLY Base class destructor.
If destructor in Base class is VIRTUAL then compiler calls derived class destructor and then Base class destructor.
If destructor in Base class is VIRTUAL then compiler calls derived class destructor and then Base class destructor.
(4)
Maytas said:
1 decade ago
Can somebody explain it?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers