Re: Overloaded Constructors
From: Richard Herring (junk_at_[127.0.0.1)
Date: 03/29/04
- Next message: Christopher Benson-Manica: "[OT] helpful hint"
- Previous message: Ahti Legonkov: "Re: macro for enum to string?"
- In reply to: Siemel Naran: "Re: Overloaded Constructors"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 29 Mar 2004 16:48:53 +0100
In message <nAI8c.39188$PY1.733824@bgtnsc05-news.ops.worldnet.att.net>,
Siemel Naran <SiemelNaran@REMOVE.att.net> writes
>"Buster" <noone@nowhere.com> wrote in message
>news:c3ue4s$s2f$1@newsg2.svr.pol.co.uk...
>> >>"Cy Edmunds" wrote
>
>> >>>So why did you use a std::auto_ptr at all?
>> >>
>> >>Good question. Just a style choice to make it clear to the reader of
>the
>> >>header file that this class does in fact own the pointer, and it's not a
>> >>just a pointer to an existing object.
>>
>> [snip]
>>
>> > Your design seems to be technically sound. However, when perusing a
>class
>> > definition I find a pointer to be scary but a std::auto_ptr to be even
>> > scarier. Since you seemed concerned about how your class "reads" (good
>for
>> > you!) you might consider eliminating this unneccesary complication.
>>
>> I vote for keeping the auto_ptr. In this instance it has excellent
>> documentary value, and it _is_ minimal. And it's not scary.
>
>In addition, the use of std::auto_ptr over a raw pointer gives us exception
>safety in the constructor, because if the member initialization list or
>constructor body throws then the destructor is not called and we would not
>delete the raw pointer. We can put try-catch blocks around the various
>constructors, but besides I don't know the notation :).
>
>As for the complication of auto_ptr's copy semantics I guess it could be
>confusing to some.
>
So why does everyone overlook boost::scoped_ptr? Distinct declaration of
ownership, exception-safe constructor, no reference-counting overhead,
and no copy semantics at all.
-- Richard Herring
- Next message: Christopher Benson-Manica: "[OT] helpful hint"
- Previous message: Ahti Legonkov: "Re: macro for enum to string?"
- In reply to: Siemel Naran: "Re: Overloaded Constructors"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|