This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Post constructor/Pre destructor hooks


>>>>> "Dave" == Dave Korn <dave.korn@artimi.com> writes:

>> On 13 August 2007 22:16, David Orchard wrote:
>> Some base classes (specifically thread base classes) would benefit from
>> being able to execute a function after the object is constructed and before
>> it is destructed. For a thread class the thread can't start until after the
>> object is constructed and must stop before the object is destructed.

Dave>   Well, how about "Deriving a subclass, overriding the c-tor and
Dave> d-tor and calling a hook function after/before calling the base
Dave> class' c/d-tor are all fundamental C++ language features that
Dave> already exist within the standard syntax" for starters?  I'm not
Dave> sure what you hope to achieve by this added synactic complexity.

I think he wants a guarantee that the hook method will be called after
all the subclass constructors have been run.  AFAIK there's no way to
do this in standard C++.

When I've had to do things like this I've either added runtime
assertions, or I've redesigned the hierarchy; the latter on the theory
that subclassing is fragile when the base class needs a lot of control
over what the subclasses do.

Tom


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]