Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 10:03, 12 December 2007.

Virtual destructor

From Forum Nokia Wiki

The virtual destructor has the same purpose as a virtual function. At runtime looking at the type of object referred by a pointer or reference it is decided which destructor to call the destructor of the base class or the destructor of the derived class.

For example, suppose B is a base class and D is a class derived from B and suppose both classes have declared their destructor as virtual. Suppose a pointer B *ptr is initialised as follows:

    B *ptr = new D();

Now the ptr is of type B* but points to an object of D. So when this object is freed or goes out of scope D's destructor will be called since the destructor's have been declared as virtual.

CBase in Symbian

C classes got their name after their ultimate precedessor, CBase class. What comes to virtual destructors is the fact the CBase has a virtual destructor by default meaning that the destructor of any classes that derive from CBase is also virtual. Which eventually means that for destruction it's enough if your pointer points simply to a CBase object and deletes it - everything will be cleaned up properly.

 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX