TITLE: Casting pointer references is dangerous PROBLEM: class alpha { ... }; class beta : public alpha { ... }; class gamma : public beta { ... }; void testfunc(alpha*& parm) { ... parm = new alpha(40); ... } int main() { gamma g(10, 20, 30); gamma *gptr = &g; testfunc((alpha*) gptr); // ^-- why is the cast necessary? } RESPONSE: Reid Ellis (rae@utcs.toronto.edu) This has to do with the fact that when you cast from a derived class to a base class, the value of the pointer can change. This has been the case since multiple inheritance came into being in C++ [and quite possibly, since before then]. In the above program, when you cast "gamma *gptr" to an "alpha*", the value of gptr may be changed to point to its "alpha part". This pointer is then passed in to testfunc(). testfunc(), which takes a reference to said pointer can now set it to point at anything that may or may not be a "gamma". Now in main() when you return from the call to testfunc(), C++ will have no idea what to do with gptr. Should it offset it back to where it was, relative to the [new] value of its "alpha" pointer? Basically, you're trying to rip out the guts of a gamma. :) As long as a gamma* has the same pointer value as its respective alpha*, your cast will work. But if, say you were to do something like this: class beta : public something, public alpha { .. }; then your cast would no longer be valid..