Friday, November 27, 2009

Reading old test

As I read farad's old test, I learned new thing about destructor of inherited class.For e.g if we have :
handle *h[4] = {new boo(10), new bee(), new boo(4.2),new bee()};
so, we have an array of 4 element which points to class handle.
each element is included different class which are inherited of class handle.
if we say
for(i=0;i<4;i++){delete h[i];}
In this case,only destructor of class handle will be called because h is pointing to class handle,except if we declare handle's destructor as a virtual.
If we say virtual in destructor of parent,child will be destroyed then parent.

No comments:

Post a Comment