Path: utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!wuarchive!usc!apple!bionet!agate!shelby!neon!pescadero.Stanford.EDU!philip From: philip@pescadero.Stanford.EDU (Philip Machanick) Newsgroups: comp.lang.c++ Subject: Re: virtual inline functions Message-ID: <1990Oct26.002211.17443@Neon.Stanford.EDU> Date: 26 Oct 90 00:22:11 GMT References: Sender: news@Neon.Stanford.EDU (USENET News System) Reply-To: philip@pescadero.stanford.edu Organization: Computer Science Department, Stanford University Lines: 28 In article , aw1r+@andrew.cmu.edu (Alfred Benjamin Woodard) writes: |> Is there any prohabition to virtual inline functions. I didn't see one |> in E&S but they don't seem to work in cfront 2.0 . It appears as if |> they are entered into the virtual table but then compiled out of the |> code that goes to the c compiler. Thus you get function declared and |> used but never defined errors. I guess what I am really asking is this |> a bug in cfont or something inherant in c++. I admit there would have |> to be some special cases inserted into the compiler to make it work |> properly but I think in certain cases it is necessary. |> In E&S p. 228 is an explanation of how calls to virtual functions are implemented. The example given is C* pc=new C; pc->g(2); results in the call (*(pc->vptr[1])) (pc,2); In other words, the virtual function is looked up via the virtual function table of the current object. This is why you can do things like replace the object by another of a derived class, and get a different effect if the virutal function is overridden. It's also why virtual functions are not inlined - you can use an array of pointers to functions to implement calls, but it's hard to see how you could get the effect of an inline. Of course, E&S only suggested an implementation - if you have a better idea, I'm sure you would make lots of people happy (including me). -- Philip Machanick philip@pescadero.stanford.edu