Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!radar!cadillac!dsouza From: dsouza@gwen.cad.mcc.com (Desmond Dsouza) Newsgroups: comp.lang.c++ Subject: Re: Virtual functions and inline Message-ID: Date: 5 Mar 91 05:13:20 GMT References: <1991Feb28.141548.2043@cs.nott.ac.uk> Sender: news@cadillac.CAD.MCC.COM Organization: MCC CAD Program, Austin, Texas Lines: 35 In-reply-to: gas@cs.nott.ac.uk's message of 28 Feb 91 14:15:48 GMT In article <1991Feb28.141548.2043@cs.nott.ac.uk> gas@cs.nott.ac.uk (Alan Shepherd) writes: > Is it okay to declare virtual functions inline ? Even though the code > to be excuted is substituted rather than a function call made, does > the correct method still get called ? It can be done, and is sometimes useful. However, in addition to the normal cautions about inlines (dont overdo, code bloat, etc), note that inline virtuals can cause a subltle problem with some compilers. Specifically, to support separate compilation, a compiler needs to decide in which object module to emit the definition of the virtual table. It could emit one in every .C file which included the class definition, but that would cause too much duplication. Alternately, some compilers use some heuristic to choose a specific object module for the vtable. e.g. select the .C file which has the DEFINITION of the alphabetically first non-virtual member function. For this heuristic, if your class has all member functions as inlines (virtual or non), you will end up with lots of duplicated vtables, or even with a missing virtual table failure at link time. -- Desmond. -- ------------------------------------------------------------------------------- Desmond D'Souza, MCC CAD Program | ARPA: dsouza@mcc.com | Phone: [512] 338-3324 Box 200195, Austin, TX 78720 | UUCP: {uunet,harvard,gatech,pyramid}!cs.utexas.edu!milano!cadillac!dsouza