How do you know that your class needs a virtual destructor?
Answer Posted / som shekhar
If we are deriving from the base class and the base class
consist of some virtual function , then in this case the
base destructor should be virtual.
if you do some thing like this :
base* b = new derived;
delete b;
In this case if base destructor is NOT VIRTUAL then only
base destructor is called and derived destructor wont be
called resulting into memory leak.
But if the base destructor is virtual then derived class
destructor and base destructor both will be called.
Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Is c++ pass by reference or value?
Is c++ the most powerful language?
What is lambda in c++?
Write about an iterator class?
What is the difference between a "copy constructor" and an "assignment operator" in C++?
Snake Game: This is normal snake game which you can find in most of the mobiles. You can develop it in Java, C/C++, C# or what ever language you know.
Mention the storage classes in c++.
Give example of a pure virtual function in c++?
Explain the concept of dynamic allocation of memory?
What are function prototypes?
What's c++ used for?
What is java and c++?
How is computer programming useful in real life?
How would you differentiate between a pre and post increment operators while overloading?
Write syntax to define friend functions in C++.