Wednesday 28 October 2009

Virtual Deconstructors!

Wow, turns out all the stuff I was going on about type casting was, while useful to know, unnecessary! When you delete a pointer of BaseClass* type which points to an InheritedClass object, all that needs to happen to get the base class to delete the inherited one correctly is to make the base class's deconstructor virtual. One word in the header file. Super easymode.

instead the VS2008 default of:

public:

BaseClass(void);
~BaseClass(void);

you have:

public:

BaseClass(void);
virtual ~BaseClass(void);

Thats IT!

Woo.

No comments:

Post a Comment