In Object Oriented Programming, Objects are the instances of a class which has its own state(variables) and behavior(methods). Every class has two special methods related… Read More
Tag Archives: C++-Destructors
Constructor: A constructor is a member function of a class that has the same name as the class name. It helps to initialize the object of… Read More
A recursive and a non-recursive program to delete an entire binary tree has already been discussed in the previous posts. In this post, deleting the… Read More
Can destructors be virtual in C++? (A) Yes (B) No Answer: (A) Explanation: See https://www.geeksforgeeks.org/g-fact-37/Quiz of this Question My Personal Notes arrow_drop_up Save
#include <iostream> using namespace std; class A { int id; static int count; public: A() { count++; id = count; cout << "constructor for id… Read More
Like constructors, can there be more than one destructors in a class? (A) Yes (B) No Answer: (B) Explanation: There can be only one destructor… Read More
Predict the output of following C++ program #include <iostream> using namespace std; int i; class A { public: ~A() { i=10; } };… Read More
Can destructors be private in C++? (A) Yes (B) No Answer: (A) Explanation: Destructors can be private. See Private Destructor for examples and uses of… Read More
Deleting a derived class object using a pointer of base class type that has a non-virtual destructor results in undefined behavior. To correct this… Read More