C++ Programming - Constructors and Destructors - Discussion
Discussion Forum : Constructors and Destructors - Programs (Q.No. 8)
8.
What will be the output of the following program?
#include<iostream.h>
class BixBase
{
public:
BixBase()
{
cout<< "Base OK. ";
}
};
class BixDerived: public BixBase
{
public:
BixDerived()
{
cout<< "Derived OK. ";
}
~BixDerived()
{
cout<< "Derived DEL. ";
}
};
int main()
{
BixBase objB;
BixDerived objD;
objD.~BixDerived();
return 0;
}
Discussion:
13 comments Page 2 of 2.
Achyut Gughane said:
1 decade ago
Guys answer is wrong because when we call destructor explicitly then system doesn't call destructor for that object so correct answer is B.
Rishabh said:
6 years ago
@All.
I tried to run the code in turbo C and I was getting error like: Member identifier expected.
Why, can anyone explain me?
I tried to run the code in turbo C and I was getting error like: Member identifier expected.
Why, can anyone explain me?
Abhishek said:
1 year ago
When the object scope is all completed then the destructor is called by the compiler itself.
that means all the memory stored by the object will be released.
But when you explicitly call the destructor with that object name then the compiler again frees the memory of that object, which may corrupt the memory.
that means all the memory stored by the object will be released.
But when you explicitly call the destructor with that object name then the compiler again frees the memory of that object, which may corrupt the memory.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers