Skip to content

Tag Archives: C++-Destructors

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
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 http://www.geeksforgeeks.org/g-fact-37/Quiz of this Question Attention reader! Don’t stop learning now. Get… Read More
#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++ progran #include <iostream> using namespace std;     int i;     class A { public:     ~A()     {         i=10;     } };… Read More
Can destuctors 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 situation,… Read More