aw1r+@andrew.cmu.edu (Alfred Benjamin Woodard) (10/26/90)
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. -ben
philip@pescadero.Stanford.EDU (Philip Machanick) (10/26/90)
In article <wb9nCeu00Voh8DQr0P@andrew.cmu.edu>, 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