Virtual calls upon destruction
Hi,
I have a class heirarchy which has a uninitialize() virtual member
function, which aught to be called upon destruction. I know that
putting it in the destructor will not work, so I came up with the
following solution. Aside from any aesthetic and maintenance problems
(I am aware of a few), is this technique portable?
class Base
{
public:
virtual ~Base ();
virtual void uninitialize ( ) = 0;
virtual void deleteMe (void * ptr, std::size_t sz)
{ ::operator delete(ptr, sz); }
// ...
static void operator delete (void * ptr, std::size_t sz)
{
if(ptr)
{
Base * bptr = reinterpret_cast<Base*>(ptr);
bptr->uninitialize();
bptr->deleteMe(ptr, sz);
}
}
};
So what the hell have I done? I am assuming that bptr will point to a
fully constructed object, and thus the correct functions will be
called. I am on a trip now, and don't have access to a compiler, so I
may be completely bonkers on this one, any comments are appreciated.
Regards,
Jeremy Jurksztowicz
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]