Re: Good style for memory management?



On Sun, 2007-03-18 at 21:01 +0100, Milosz Derezynski wrote:
> Is there any particular reason you're not passing the args to the
> ctor? As we all know C++ rather likes
> init-with-ctor-rather-than-init()-method

C++ might, but lots of experts with real life experience of C++ in cases
where exception-during-construction is real and problematic suggest that
the init-with-ctor doesn't fit well in that scenario. There are other
cases where it doesn't fit either (for example, deserializing from
something like XML which tends to promote HAS-A relationships but your
objects are all inheritance based (IS-A)).

i agree with you that if its not so much of an issue, then you
suggestion of:

    MyFancyWidget* w = 0;

    try {
        w = manage (new MyFancyWidget(some, args, it, might, need));
    }
    catch (....

is perfectly sensible.

--p





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]