Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!bellcore!faline!thumper!ulysses!hector!jss From: jss@hector.UUCP (Jerry Schwarz) Newsgroups: comp.lang.c++ Subject: Re: cant use virtuals in base constructors Message-ID: <11492@ulysses.homer.nj.att.com> Date: 5 May 89 13:56:06 GMT References: Sender: netnews@ulysses.homer.nj.att.com Reply-To: jss@hector.UUCP (Jerry Schwarz) Distribution: comp Organization: AT&T Bell Laboratories Lines: 27 In article dove@rocket.stars.flab.Fujitsu.JUNET (Webster Dove) writes: > The reasons for calls to a virtual member function in a base constructor to be made to the base version of the virtual have been discussed in this group several times recently. In summary, its because the members added in the derived class have not yet been initialized. > >Consider the case of someone implementing a base class for others to >use (e.g. an error handler). I wanted to use this technique to tell >at construction time that a derived class had failed to implement its >own method for something (e.g. type_string()). I would do this by >invoking the virtual in the base constructor, and having a dummy >method in the base class that I could detect. > In the pre-release of 2.0 there is a way to detect this at compile time. class B { public: virtual void f() = 0 ; // f must be supplanted in all // derived classes. Allocation of // a B (directly or via new) is not // allowed. } ;