home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!Germany.EU.net!urmel.informatik.rwth-aachen.de!tabaqui!dak
- From: dak@tabaqui.informatik.rwth-aachen.de (David Kastrup)
- Newsgroups: comp.lang.c++
- Subject: Re: Is this C++ advice from an OO book true? (beginner question)
- Date: 24 Jan 93 10:11:42 GMT
- Organization: Rechnerbetrieb Informatik - RWTH Aachen
- Lines: 27
- Distribution: world
- Message-ID: <dak.727870302@tabaqui>
- References: <sherman.727849469@foster>
- NNTP-Posting-Host: tabaqui.informatik.rwth-aachen.de
-
- sherman@unx.sas.com (Chris Sherman) writes:
-
- >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)!
-
-
- >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!
-
- And the above book writes a beginner's answer. Constructors cannot be
- virtual and I pity the poor fools who have to spend nights and weekends
- only to find out that in C++ the type system is static, and so every
- object's type is fixed from the beginning and types are managed by
- the compiler. If the runtime had anything to do with the type system in
- C++, maybe there would be such a thing as a virtual constructor.
-