Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!ucsd!ames!sgi!dragon!xanadu.wpd.sgi.com!pal From: pal@xanadu.wpd.sgi.com (Anil Pal) Newsgroups: comp.lang.c++ Subject: Re: Virtual functions used in constructor illegal ! ?? Keywords: virtual functions, constructor Message-ID: <1990Dec5.014357.17601@relay.wpd.sgi.com> Date: 5 Dec 90 01:43:57 GMT References: <822@orthogo.UUCP> <39733@ucbvax.BERKELEY.EDU> <27556AD1.350C@tct.uucp> Sender: news@relay.wpd.sgi.com ( CNews Account ) Reply-To: pal@sgi.com Organization: Silicon Graphics, Inc. Lines: 26 In article <27556AD1.350C@tct.uucp>, chip@tct.uucp (Chip Salzenberg) writes: [ Referring to constructor calling base class virtual function] |> This is true, but only if you are calling the virtual function from |> the actual constructor function body. If you call a virtual function |> from a constructor by other means, such as calling a function that |> calls the virtual function, E&S says that the behavior is undefined, |> i.e. all bets are off. Are you sure about this? My copy of E&S says (page 294, sec. 12.7) Member functions may be called in constructors and destructors. This implies that virtual functions may be called (DIRECTLY OR INDIRECTLY [emphasis mine]). The function called will be the one defined in the constructor's (or destructor's) own class or its bases, but *not* any function overriding it in a derived class. [...] The effect of calling a PURE [emphasis mine] virtual function directly or indirectly [...] is undefined. If what you say is in fact stated somewhere else in E&S, then there is a definite contradiction. -- Anil A. Pal, Silicon Graphics, Inc. pal@sgi.com (415)-335-7279 Brought to you by Super Global Mega Corp .com