Re: Overloaded Constructors
From: Cy Edmunds (cedmunds_at_spamless.rochester.rr.com)
Date: 03/25/04
- Next message: Old Wolf: "Re: Another glass of STL whine"
- Previous message: Old Wolf: "Re: Another glass of STL whine"
- In reply to: Siemel Naran: "Re: Overloaded Constructors"
- Next in thread: Buster: "Re: Overloaded Constructors"
- Reply: Buster: "Re: Overloaded Constructors"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 25 Mar 2004 04:47:24 GMT
"Siemel Naran" <SiemelNaran@REMOVE.att.net> wrote in message
news:D8k8c.14644$tY6.427566@bgtnsc04-news.ops.worldnet.att.net...
> "Cy Edmunds" <cedmunds@spamless.rochester.rr.com> wrote in message
> news:Cnj8c.53506
> > "Siemel Naran" <SiemelNaran@REMOVE.att.net> wrote in message
>
> > > > > class User {
> > > > > public:
> > > > > ~User();
> > > > > User (string full_username);
> > > > > User (string user, string domain);
> > > > > User (const User&);
> > > > > User& operator=(const User&);
> > > > > private:
> > > > > struct Imp;
> > > > > std::auto_ptr<Imp> d_imp;
> > > > > };
>
> > 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.
The reader of your header file should try to ignore implementation details
and focus on your interface and documentation. However, real people don't
necessarily take that advice, and when they see std::auto_ptr may feel it
necessary to check over your code to make sure of the copy semantics.
> The boost::shared_ptr gives me
> reference counting for free, but if I don't need that feature I won't use
> it. Big deal -- I save about 4 bytes, whereas the size of Imp may be so
> large, that saving 4 bytes is nothing. Anyway, my style is to prefer the
> object that is minimal for my purpose.
In this case, that would be a pointer.
> In a big project I will adapt my
> style in order to have a single rule for all objects, as a uniform coding
> standard will make code easier to maintain down the road.
>
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.
-- Cy http://home.rochester.rr.com/cyhome/
- Next message: Old Wolf: "Re: Another glass of STL whine"
- Previous message: Old Wolf: "Re: Another glass of STL whine"
- In reply to: Siemel Naran: "Re: Overloaded Constructors"
- Next in thread: Buster: "Re: Overloaded Constructors"
- Reply: Buster: "Re: Overloaded Constructors"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|