home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 19840 < prev    next >
Encoding:
Internet Message Format  |  1993-01-24  |  2.4 KB

  1. Path: sparky!uunet!cimshop!davidm
  2. From: davidm@consilium.com (David S. Masterson)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Is this C++ advice from an OO book true?  (beginner question)
  5. Message-ID: <DAVIDM.93Jan24144315@consilium.com>
  6. Date: 24 Jan 93 22:43:15 GMT
  7. References: <sherman.727849469@foster>
  8. Sender: root@cimshop.UUCP
  9. Distribution: comp
  10. Organization: Consilium Inc., Mountain View, California
  11. Lines: 36
  12. In-reply-to: sherman@unx.sas.com's message of 24 Jan 93 04:24:29 GMT
  13. X-Posting-Software: GNUS 3.13  [ NNTP-based News Reader for GNU Emacs ]
  14.  
  15. >>>>> On 24 Jan 93 04:24:29 GMT, sherman@unx.sas.com (Chris Sherman) said:
  16.  
  17. > I read the following from a book that adviced how to do software projects
  18. > using OO-type languages.  In one of the appendixes, it gave some advice
  19. > on how to write C++ programs.  
  20.  
  21. > I don't understand one of the book's recommendations:
  22.  
  23. >   11.  Call virtual class constructors in derived class constructors.
  24.  
  25. I ran into this problem recently while designing an ostream class when I tried
  26. to figure out how things worked.  The key words in the recommendation that are
  27. causing you trouble are "virtual class".
  28.  
  29. In the case of a base class, derived classes need not worry about how their
  30. immediate ancestors derive from other classes -- their base classes will take
  31. care of that.  However, with "virtual" base classes, there is only one copy of
  32. this base class in an object, so the question is which of the potentially many
  33. classes that make up the object is responsible for instantiating that virtual
  34. base class?  The answer is that, since there can only be a one for one
  35. relationship between the object being instantiated and its class definition,
  36. the class definition of the object must take responsibility for instantiating
  37. the one copy of the virtual base class.  Therefore, every class that is
  38. derived from a virtual base class must take responsibility for instantiating
  39. that virtual base class (even if it doesn't, its equivalent to calling the
  40. virtual base classes NULL constructor).
  41. --
  42. ====================================================================
  43. David Masterson                    Consilium, Inc.
  44. (415) 691-6311                    640 Clyde Ct.
  45. davidm@consilium.com                Mtn. View, CA  94043
  46. ====================================================================
  47. I'm opposed to these unsupervised weekend furloughs for first-degree
  48. murderers.
  49.                 -- George Bush, asked whether the Pledge of Allegiance
  50.                    would be his only campaign issue in 1988.
  51.