Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ncar!boulder!stan!garya From: garya@Solbourne.COM (Gary Aitken) Newsgroups: comp.lang.c++ Subject: address of virtual function (revisited) Message-ID: <904@garya.Solbourne.COM> Date: 28 Apr 89 17:41:57 GMT Organization: Solbourne Computer Inc., Longmont, Co. Lines: 44 Jonathan Shopiro's response to my earlier posting is a help in terms of dereferencing the pointers once they have been given the proper values. However, I don't see any solution (yet) to the problem of getting the proper values in the pointers in the first place. How does one get the address of the virtual function for an object, given a pointer to the object? class A { public: virtual void f() ; } class B : public A { public: void f() ; } typedef void A::MEMF() ; // type for "member function of A" MEMF *fp ; B *bp = new B ; A *objp = (A*) bp ; fp = &objp->f ; // if objp is REALLY a *A, I want &A::f // but if it's REALLY a *B, I want &B::f // again, this works in cfront, with warnings... /* I don't want fp = &A::f because I need the appropriate virtual function to dispatch when the function call is made. */ Or am I missing something here? If I do fp = &A::f and subsequently do a (bp->*fp)() will this somehow go through the virtual table and actually call B::f if bp is REALLY a B* object pointer? (I can't test this right now because our cfront is broken for these constructs right now...) -- Gary Aitken Solbourne Computer Inc. ARPA: garya@Solbourne.COM Longmont, CO UUCP: ...!{boulder,sun}!stan!garya