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