Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!samsung!munnari.oz.au!metro!wolfen!pejn From: pejn@wolfen.cc.uow.oz (Paul Nulsen) Newsgroups: comp.lang.c++ Subject: Re: Efficient compilation of virtual functions Message-ID: <6428@wolfen.cc.uow.oz> Date: 22 Aug 90 23:40:48 GMT References: <1990Aug22.193347.18486@ux1.cso.uiuc.edu> Organization: Uni of Wollongong, NSW, Australia Lines: 25 nelson@suna2 (Taed Nelson) writes: > ... >If we have a virtual member function in the base class, and the same member > function is redeclared in the subclass, whenever we are using an instance > of the subclass, there is _no need_ to consult the virtual function table > since we will _always_ call the subclass function. > ... > base *basePointer = new base; > subclass *subclassPointer = new subclass; > base *indirectPointer = new subclass; > basePointer->mutate(); > subclassPointer->mutate(); // this should be optimized/inlined > indirectPointer->mutate(); This is not as straightforward as you suggest: subclass may have another class derived from it, in which case subclassPointer->mutate() is ambiguous and must be resolved via the virtual function table. The problem then is that the compiler needs to know that subclass has nothing derived from it. This is not possible with separate compilation. Paul Nulsen pejn@wolfen.cc.uow.edu.au