Declare virtual destructor for the polymorphism base class (declare Destructors virtual in polymophic base classes .)
If the base class has a non-virtual destructor, the result of deleting a derived class via the base class pointer is defined, which will cause partial destruction of the object: the base class part is destroyed, while the derived part is destroyed.
If you declare a virtual destructor for the class without reason, the object size will be increased. Some operations cannot be performed (mainly conversions involving internal details ).
Virtual destructor are declared only when the class contains at least one virtual function.
Do not integrate any classes without virtual destructor. C ++ does not provide a mechanism similar to Java to prohibit derivation.
Destructor are called at the deepest level, and then the destructor of base class is called.
A virtual destructor for base classes. This rule applies only to polymorphic (with polymorphism) base classes. The purpose is to process the derived classes object through the base classes interface.
Concurrent all base
Classes are used for Polymorphism purposes. Non-polymorphism uses base classes without virtual destructor.
Note:
Ø
Polyphonic (with polymorphism) base classes should declare a virtual destructor. If the class has any virtual function, it should have a virtual destructor.
Ø
Classes should not be declared if it is not used as a base class or for polymorphism (polyphonically.