Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!dptg!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c++ Subject: Re: swapping virtual function table pointers Message-ID: <9802@alice.UUCP> Date: 22 Aug 89 12:32:28 GMT References: <2438@cadillac.CAD.MCC.COM> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 24 In article <2438@cadillac.CAD.MCC.COM>, vaughan@puma.cad.mcc.com (Paul Vaughan) writes: > I occasionally have related classes with identical data and > function members but differing virtual function definitions. I'd like > to be able to change the behavior of objects of such classes by > changing the virtual function table pointer in the existing objects. C++ does not support that operation. Objects do not have mutable types. If you try it, you get what you get. Sorry about that. Consider, for instance, a C++ implementation that distinguishes between objects of different types by reserving a separate block of (virtual) memory for each type and using the address of the object to figure out how to resolve virtual function calls. Such an implementation would not have any virtual function tables at all, which would make it hard to change it. You may be able to achieve a similar effect in some C++ implementations by various kinds of pointer cheating. There is no guarantee that any such hack will continue to work, and I'm reluctant even to give advice as to how to do it. -- --Andrew Koenig ark@europa.att.com