when can we use virtual destructor?
Answer Posted / sagarson
Need for a virtual destructor
1.destructor for the base parts are invoked automatically
2.we might delete a ptr to the base type that actually
points to a derived object
3.if we delete a ptr to base then the base class destructor
is run and the members of the base class are cleared up. If
the object is a derived type then the behavior is undefined
4.to ensure that the proper destructor is run the destructor
must be virtual in the base class
5.virtual destructor needed if base pointer that points to a
derived object is ever deleted (even if it doesnt do any work)
| Is This Answer Correct ? | 34 Yes | 4 No |
Post New Answer View All Answers
What is the basic difference between C and C++?
Why do we use pointers in c++?
What you know about structures in C++?
What is #include c++?
What is a .lib file in c++?
Can there be at least some solution to determine the number of arguments passed to a variable argument list function?
What are the operators in c++?
Write is a binary search tree? Write an algo and tell complexity?
What is the keyword auto for?
the first character in the variable name must be an a) special symbol b) number c) alphabet
Ask to write virtual base class code?
If a round rectangle has straight edges and rounded corners, your roundrect class inherits both from rectangle and from circle, and they in turn both inherit from shape, how many shapes are created when you create a roundrect?
What is an arraylist c++?
What is an inline function in c++?
Is c++ a low level language?