Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!ucbvax!ulysses!hector!jss From: jss@hector.UUCP (Jerry Schwarz) Newsgroups: comp.lang.c++ Subject: Re: What is C++ doing? Keywords: behind my back in C, that is... Message-ID: <11565@ulysses.homer.nj.att.com> Date: 20 May 89 17:08:00 GMT References: <2671@ssc-vax.UUCP> Sender: netnews@ulysses.homer.nj.att.com Reply-To: jss@hector.UUCP (Jerry Schwarz) Organization: AT&T Bell Laboratories Lines: 33 In article <2671@ssc-vax.UUCP> dmg@ssc-vax.UUCP (David Geary) writes: > > Anyway, Jerry's posting is a perfect example of my ignorance ;-). >What *is* a _vptr? I have also heard reference to the VTABLE >in previous postings. What are these animals? > When a class has virtual member functions its representation contains a pointer (called a virtual pointer, or "vptr" for short) to a table (called a virtual table or "vtbl" for short) that has entries indicating the actual functions to be called when a virtual function is called. Thus given something like struct Base { virtual void f() ; } ; struct Derived : public Base { void f() ; } ; void fct(Base* b) { b->f() ; } // actual call involves using vptr to find the vtbl // entry that says exactly how to invoke f. // This is neccessary because Base::f or Derived::f // must be called depending on whether b points to an // object that was allocated as a Base or as a Derived. Jerry Schwarz AT&T Bell Labs, Murray Hill