Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!decvax!savax!dove From: dove@rocket.stars.flab.Fujitsu.JUNET (Webster Dove) Newsgroups: comp.lang.c++ Subject: Re: fixing pitfall in virtual members Message-ID: Date: 23 Feb 89 12:42:00 GMT References: <91@riunite.ACA.MCC.COM> Sender: news@savax.UUCP Distribution: comp Organization: Sanders Advanced Technology Dept. Lines: 32 In-reply-to: rfg@riunite.ACA.MCC.COM's message of 18 Feb 89 21:49:44 GMT Posting-Front-End: GNU Emacs 18.44.4 of Tue May 12 1987 on rocket (berkeley-unix) In article <91@riunite.ACA.MCC.COM> rfg@riunite.ACA.MCC.COM (Ron Guilmette) writes: Please correct me if I am wrong, but couldn't you have avoided your trouble if you had defined the "default" virtual member function in the base class to do something which would let you know that it had been called by mistake, e.g. calling abort() or something? Yes. Exactly my advice when we write the base class (also recommended by johnson@p.cs.uiuc.edu). However, in this case, the base was written by Mark Linton and at least at the time he did not recognize the risk. That is what I do when I have virtual member function declared in a base class which are just there as "placeholders" are which are not supposed to be called in practice. That will detect at run time a failure to overload the base virtual definition. I guess barring a change to the language, I would prefer a compiler warning of the form recommended by Andrew Koenig: Issue a warning when a non-virtual function declaration hides a virtual function with the same name declared in a base class. This would detect the problem at compile time, and could be added to a compiler as a switch (as the -fsingle switch was added to correct the single to double conversion misfeature in C). -- Dr. Webster Dove Computing Systems and Architectures Advanced Signal Processing Engineering (ASPEN) Dept. Sanders Associates (a Lockheed Company)