Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!bellcore!faline!thumper!ulysses!andante!alice!shopiro From: shopiro@alice.UUCP (Jonathan Shopiro) Newsgroups: comp.lang.c++ Subject: Re: ptr to member function, even worse Summary: ``Object'' is not a type Message-ID: <9302@alice.UUCP> Date: 4 May 89 15:48:13 GMT References: <937@garya.Solbourne.COM> Organization: AT&T Bell Laboratories, Murray Hill NJ Lines: 51 In article <937@garya.Solbourne.COM>, garya@Solbourne.COM (Gary Aitken) writes: > OK, everyone has been real helpful and with a few patches and fixes we've > managed to figure out what g++ and cfront are doing with address of > virtual function references. But the whole problem is even worse than > I originally mentioned... > > Consider a function > > dispatch(objp,fnp) > > which has very little knowledge of its arguments. It knows the following: > > objp is a pointer to a C++ object > fnp is a pointer to a member function for objp (possibly virtual) > > In particular, dispatch has no knowledge of the base class for objp. > None of the methods/syntax discussed so far will allow dispatch to call > fnp on behalf of objp. The code generated by cfront assumes knowledge > of where the virtual table is located based on the base class type; > the virtual table offset is not in a constant place. You understand part of the problem correctly. The other part is that it is fundamental to C++ that every operation is type-safe, either because the compiler can prove it, or because the programmer has asserted it with a cast. There are no type-variables in C++, so there is no way of asserting that fnp points to a member function of the class of whatever objp points to. Thus there is no portable solution in C++ for the problem as you have stated it, and I believe there is no solution at all in AT&T C++ 2.0. The best alternative is to be sure that dispatch knows at least the base class of objp, either by defining a ``universal'' base class, or by overloading dispatch (perhaps parameterizing it). s o r r y a b o u t t h i s -- Jonathan Shopiro AT&T Bell Laboratories, Warren, NJ 07060-0908 research!shopiro (201) 580-4229