home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18714 < prev    next >
Encoding:
Text File  |  1993-01-05  |  1.3 KB  |  34 lines

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