Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!pasteur!ucbvax!decwrl!decvax!savax!dove From: dove@rocket.stars.flab.Fujitsu.JUNET (Webster Dove) Newsgroups: comp.lang.c++ Subject: fixing pitfall in virtual members Message-ID: Date: 14 Feb 89 03:21:34 GMT Sender: news@savax.UUCP Distribution: comp Organization: Sanders Advanced Technology Dept. Lines: 38 Posting-Front-End: GNU Emacs 18.44.4 of Tue May 12 1987 on rocket (berkeley-unix) I have recently had two staff waste a day each chasing very similar problems with virtual members. I believe a minor change to the language definition could eliminate a significant pitfall that now exists. Both people were working on Interviews applications. Mike was trying to upgrade an old application to a new Interviews rev. Kevin was writing a new application. Part of the both applications required that the programmer create a virtual function member in a class they wrote that would catch an event (exposure I believe). Unfortunately, in Mike's case, the syntax of the call had changed between revs and in Kevin's case, the documented syntax was wrong. The result was that the function members they had declared were considered new members (as opposed to shadowing virtuals from the base class) and were never called because their syntax was not the required one. Since C++ requires that the base class provide a default member, the package has one which does nothing. Therefore, the programs compiled without any warnings. However, when they were run the results were very obscure behaviors that took considerable skill and effort to diagnose. My recommendation is the following: eliminate the requirement to restate the syntax of virtual functions in the derived class declaration. If they must be restated, require the keyword "shadow" in front to explicitly connote that the declaration must "hook up" with an identical virtual declaration in the base class. This would have given my two staff obvious syntax errors to correct and reduced the expended time by orders of magnitude. I must emphasize that these were both competent people who independently ran into the same problem. It suggests to me a substantial risk in using the language. -- Dr. Webster Dove Computing Systems and Architectures Advanced Signal Processing Engineering (ASPEN) Dept. Sanders Associates (a Lockheed Company)