Boost logo

Boost :

From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2004-05-28 07:14:35


"Johan Nilsson" <johan.nilsson_at_[hidden]> wrote in message
news:c96p5d$qlg$1_at_sea.gmane.org...
>
> "Andreas Huber" <ah2003_at_[hidden]> wrote in message
> news:loom.20040527T133057-890_at_post.gmane.org...
> > Johan Nilsson <johan.nilsson <at> esrange.ssc.se> writes:
> >
> > > What's stopping me from always create them in constructor/delete in
> > > destructor, then just init/deinit them (if necessary) in entry/exit?
> >
> > The fact that most classes (well-designed ones) don't have init/deinit.
> >
>
> I'm totally aware of the RAII idom and didn't literally mean that the
> classes had init/deinit methods which would
> totally initialize and clean up the state. I referred to actions
> (_manipulating_ already created members: classes/pods/built-ins) that
> _might_ be necessary to call depending on the state in question.
>
> Ideally a state should be state-less, right? Once created it should always
> be able to execute the same actions no matter when in time. IRL there's
more
> likely something that needs to be done to initiate the state. Does it
matter
> if this is a two-step procedure:
>
> Allocate in constructors + Initialize in entry
>
> or one-step:
>
> Allocate and initialize in constructor.

class astate : non_copyable
{
    T& mRef;

    astate();

public:

    astate( T& aRef ):mRef(aRef){ aRef.somefunction(); }

    void init( T& aRef ){ mRef = aRef; mRef.somefunction(); } // not the
same

};

Jeff Flinn


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk