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


On 13 August 2007 22:16, David Orchard wrote:

> Hi,
> 
>     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.
> 
>     Does such a (probably non-standard) feature already exist or am I
> missing something.

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

> a) There can be only one class in any class hierarchy with the 'hooks' 
> property.

  Pretty hard to enforce at compile time.

> All though the base class could implement a mechanism for 
> derived classes to have hooks. But this is an application issue.

  You just keep on redescribing what seems to me like the standard behaviour
of classes with derived and overridden functions.

> c) It is not manditory but advisable to disable the copy constructor for all

> 'hook' classes.

  Well, or to implement one that DTRT.

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


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