home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!walter!grumpy!bytor
- From: bytor@grumpy.NoSubdomain.NoDomain (Ross Huitt)
- Subject: Re: How to prevent local instances, but allow "new"
- Message-ID: <1993Jan5.185612.17383@walter.bellcore.com>
- Sender: bytor@grumpy (Ross Huitt)
- Nntp-Posting-Host: grumpy.ctt.bellcore.com
- Organization: Bellcore
- References: <1icij0INNdhc@news.cerf.net>
- Date: Tue, 5 Jan 93 18:56:12 GMT
- Lines: 21
-
- In article <1icij0INNdhc@news.cerf.net>, hlf@nic.cerf.net (Howard Ferguson) writes:
- ....
- |> I suppose writing a satic member function called "createSomething"
- |> which would then call a private constructor via new woulod work,
- |> but it seems a little kludgy. I want my library users to create
- |> their objects using new, as our creator intended, rather
- |> than calling some non-standard function.
-
- Actually, I find myself using static 'create' methods more frequently these days.
- If there is any chance at all that the constructor might fail, this is almost a
- necessity. Sure, you can use exception handling for this task, but in many cases
- this would be more 'abuse' than 'use'. Returning a NULL pointer is often enough
- information about the failure. If I need more than this, I'll throw a
- 'precondition_failure' exception or whatever is appropriate for the situation.
-
- ...
- |> tanx,
- |> hlf
- |>
-
- -bytor
-