Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!swrinde!ucsd!ucbvax!galileo.berkeley.edu!jbuck From: jbuck@galileo.berkeley.edu (Joe Buck) Newsgroups: comp.lang.c++ Subject: Re: Virtual functions used in constructor illegal ! ?? Keywords: virtual functions, constructor Message-ID: <39733@ucbvax.BERKELEY.EDU> Date: 26 Nov 90 20:21:11 GMT References: <822@orthogo.UUCP> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: jbuck@galileo.berkeley.edu (Joe Buck) Lines: 33 Not illegal, they just don't do what you think. In article <822@orthogo.UUCP>, basti@orthogo.UUCP (Sebastian Wangnick) writes: > I just recognized that my cfront 2.0 installs the vtable > of a derived class only *after* the constructor of the > base class is called. > This implies that you are not allowed to use virtual member > functions within the constructor of an abstract base class. This is documented in Ellis and Stroustrup's Annotated C++ Reference Manual, which the ANSI committee is using as the base document for the official standard. The standard actually says that if you do call a virtual method in the constructor, that the base class method is always called, even if you redefine the method. That is, if you have class Derived: public Base { ... } any virtual methods you call in the constructor for Derived act as though the object were of type Base. > Now: Is this a bug or a feature ?? It's a feature (and a required one at that). Any compiler that does what you want violates the standard. -- Joe Buck jbuck@galileo.berkeley.edu {uunet,ucbvax}!galileo.berkeley.edu!jbuck