home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 19817 < prev    next >
Encoding:
Text File  |  1993-01-24  |  1.9 KB  |  45 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!gatech!concert!sas!mozart.unx.sas.com!foster!sherman
  3. From: sherman@unx.sas.com (Chris Sherman)
  4. Subject: Is this C++ advice from an OO book true?  (beginner question)
  5. Sender: news@unx.sas.com (Noter of Newsworthy Events)
  6. Message-ID: <sherman.727849469@foster>
  7. Date: Sun, 24 Jan 1993 04:24:29 GMT
  8. Nntp-Posting-Host: foster.unx.sas.com
  9. Organization: SAS Institute Inc.
  10. Lines: 33
  11.  
  12. I read the following from a book that adviced how to do software projects
  13. using OO-type languages.  In one of the appendixes, it gave some advice
  14. on how to write C++ programs.  
  15.  
  16. I don't understand one of the book's recommendations:
  17.  
  18.   11.  Call virtual class constructors in dervied class constructors.
  19.  
  20.      I pity the poor fools who have to spend nights and weekends searching
  21.      for the reason that a class variable occasionally takes on strange,
  22.      unexpected values .  .  .  only to find through their bleary eyes
  23.      that they forgot to allocate space for a virtual base (super) class,
  24.      so that storage is allocated for the base class's members.  Even if
  25.      the class has no members, declare it--you never know what future
  26.      changes will come back to haunt you (or the person who inherits your
  27.      mine field)!
  28.  
  29.  
  30. Now, I thought that a contructor will allocate everything it needs, even
  31. if it inherits from other classes.  I never heard that you had to call
  32. all the constructors in all the bases classes manually.  This kind of
  33. blows the idea that a class shouldn't have to explicitly know who its
  34. parents are, right?
  35.  
  36. Or if this is very good advice, could someone give an example showing why
  37. it is true?
  38.  
  39. This is a beginner question obviously--thanx for any help!
  40. -- 
  41.      ____/     /     /     __  /    _  _/    ____/
  42.     /         /     /     /   /      /     /          Chris Sherman
  43.    /         ___   /        _/      /          /
  44.  _____/   __/   __/   __/ _\    _____/   _____/           sherman@unx.sas.com
  45.