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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!enterpoop.mit.edu!senator-bedfellow.mit.edu!bloom-picayune.mit.edu!space.mit.edu!berczuk
  3. From: berczuk@space.mit.edu (Steve Berczuk)
  4. Subject: Re: Preventing inheritance
  5. Message-ID: <1993Jan11.195503.6255@athena.mit.edu>
  6. Sender: news@athena.mit.edu (News system)
  7. Nntp-Posting-Host: plantagenet.mit.edu
  8. Organization: MIT Center for Space Research
  9. References:  <1iqtnpINN283@news.cerf.net>
  10. Date: Mon, 11 Jan 1993 19:55:03 GMT
  11. Lines: 33
  12.  
  13. In article <1iqtnpINN283@news.cerf.net>, hlf@nic.cerf.net (Howard Ferguson) writes:
  14. |> 
  15. |> If I create a class which I am supplying to other users, how do I
  16. |> make sure that they do not inherit from it ever. I could overload new
  17. |> and check the size of the object that is being allocated, but there
  18. |> are two catchs. The first minor one is that this is a run-time check,
  19. |> and it would be far preferable to catch this sort of thing at compile
  20. |> time. More seriously, they could over-ride the new operator and by-pass
  21. |> the check.
  22. |>     yours totally paranoid,
  23. |>             hlf
  24. Umm, why would you want to do this?
  25.  
  26. It seems like soing this sort of thing defeats the purpose fo using c++; I can
  27. understand not wanting to "support" other users who inherit the class, but that
  28. might be best approached by some sort of documentation (eg comments in the header
  29. to the effect of "this class supports some wierd protocols that subclasses need to
  30. enforce, subclass at your own risk"). 
  31.  
  32. It is probably better to just ensure that instances of the class are  always in a
  33. consistent state.
  34.  
  35. Is there are really valid reason (aside from paranoia) that one would want to write
  36. a class that could not be subclassed?
  37.  
  38.  
  39.  
  40.  
  41.  
  42. -- 
  43. Steve Berczuk            berczuk@mit.edu        
  44. MIT Center for Space Research    (617) 253-3840
  45.  
  46.