Re: Virtual calls upon destruction
It sounds like you're confusing operator delete (the memory
deallocation function which can be overridden globally or at the class
level) with the delete operator (which calls the destructor of an
object, then calls operator delete to free the object's memory, and is
not overridable).
That was it, thanks a lot!
Just out of curiosity, would such a beast work?
class Base
{
typedef boost::function<void(void)> Uniniter;
Uniniter uninit_;
public:
Base(Uniniter const& u): _uninit(u) { }
virtual ~Base ( ) { uninit_(); }
virtual void uninitialize ( ) = 0;
};
class Derived : public Base
{
public:
Derived ( ): Base(boost::bind(&Derived::uninitialize, this)) { }
void uninitialize ( );
};
Now I wonder, would the bound 'this' parameter in Derived's consruction
be valid during ~Base()? By the time ~Base() is run I assume that
~Derived() has already run, but does this 'unwind' the vptr, or by some
other method make Derived::uninitialize() uncallable (or unsafe)? I am
aware that poiner to member functions are weird, and are supposed to
display polymorphic behavior, but in this case I am boost::binding
right to the function I want called. Let me say again, just curious.
Anyways, your suggestion of using a deleteMe() member function seems
much more sane to me, and since I already use shared_ptr for the
objects, painless to implement. Thanks again.
Regards,
Jeremy Jurksztowicz
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]