home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cimshop!davidm
- From: davidm@consilium.com (David S. Masterson)
- Newsgroups: comp.lang.c++
- Subject: Re: Is this C++ advice from an OO book true? (beginner question)
- Message-ID: <DAVIDM.93Jan24144315@consilium.com>
- Date: 24 Jan 93 22:43:15 GMT
- References: <sherman.727849469@foster>
- Sender: root@cimshop.UUCP
- Distribution: comp
- Organization: Consilium Inc., Mountain View, California
- Lines: 36
- In-reply-to: sherman@unx.sas.com's message of 24 Jan 93 04:24:29 GMT
- X-Posting-Software: GNUS 3.13 [ NNTP-based News Reader for GNU Emacs ]
-
- >>>>> On 24 Jan 93 04:24:29 GMT, sherman@unx.sas.com (Chris Sherman) said:
-
- > 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 derived class constructors.
-
- I ran into this problem recently while designing an ostream class when I tried
- to figure out how things worked. The key words in the recommendation that are
- causing you trouble are "virtual class".
-
- In the case of a base class, derived classes need not worry about how their
- immediate ancestors derive from other classes -- their base classes will take
- care of that. However, with "virtual" base classes, there is only one copy of
- this base class in an object, so the question is which of the potentially many
- classes that make up the object is responsible for instantiating that virtual
- base class? The answer is that, since there can only be a one for one
- relationship between the object being instantiated and its class definition,
- the class definition of the object must take responsibility for instantiating
- the one copy of the virtual base class. Therefore, every class that is
- derived from a virtual base class must take responsibility for instantiating
- that virtual base class (even if it doesn't, its equivalent to calling the
- virtual base classes NULL constructor).
- --
- ====================================================================
- David Masterson Consilium, Inc.
- (415) 691-6311 640 Clyde Ct.
- davidm@consilium.com Mtn. View, CA 94043
- ====================================================================
- I'm opposed to these unsupervised weekend furloughs for first-degree
- murderers.
- -- George Bush, asked whether the Pledge of Allegiance
- would be his only campaign issue in 1988.
-