Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!brutus.cs.uiuc.edu!apple!rutgers!gatech!bloom-beacon!eru!luth!sunic!mcsun!hp4nl!kunivv1!atcmpe!leo From: leo@atcmp.nl (Leo Willems) Newsgroups: comp.lang.c++ Subject: ->* and type info for virtual functions Keywords: virtual functions typeinfo Message-ID: <536@atcmpe.atcmp.nl> Date: 25 Sep 89 22:08:56 GMT Organization: AT Computing, Nijmegen, The Netherlands Lines: 42 In the following program a class object its address is put in to a void pointer. After restoring this pointer into a pointer of the base class, typeinfo seems to be restored: class B{ public: virtual void prt(){ cout << "a B\n"; } }; class D : public B{ public: void prt(){ cout << "a D\n"; } }; typedef void (B::*PF)(); main() { PF pf = B::prt; B* bp = new D; void* x = bp; // loosing type info bp = (B*) x; // returning type info? (bp->*pf)(); // bp->D::prt() ! // which is what I want (and expect) } (It works under g++ 1.35.0, it does not compile under 1.2E glockenspiel due to a ternary operator problem in the generated C code. After patching that to an if statement it compiles but calls bp->B::prt(), it lost typeinfo somewhere) Is this example program considered to be legal in C++ ( rel. 12.E and up)? Leo Willems Internet: leo@atcmp.nl AT Computing UUCP: mcvax!hp4nl!kunivv1!atcmpe!leo P. O. Box 1428 6501 BK Nijmegen Phone: +31-80-566880 The Netherlands Fax: +31-80-555887