Saturday, June 9, 2007

item 7

declare destructors virtual in polymorphic base classes

a factory function is a function that returns a base class pointer to a newly created derived class object.

to make sure that when a derived class object is deleted from a base class pointer than the entire object is deleted and not only the base class part of the object ( which is undefined....c++ doesnt define delete semantics when a base class destructor is called on a derived class object).

any class with virtual functions should almost certainly have a virtual constructor.

if a class doesnt have virtual fns than dont make the destructor virtual.

u can declare a pure virtual destructor to make a class abstract

things to remember:
plymorphic base classes should declare virtual destructors. if a class has virtual functions, it should have a virtual destructor.

classes not designd to be base classes or not designed to be used ploymorphically should not declare virtual destructors

No comments: