TITLE: What goes on in casting pointers? PROBLEM: alan@saturn.cs.swin.oz.au (Alan Christiansen) [ ... ] class A *a; class F *f; f = a; if ( (void *)f != (void *)a ) sometimes these are not equal! RESPONSE: cs931003@ariel.yorku.ca (ANETA COSTIN), 27 Aug 93 cs931003, aka Jonathan Shekter, from sunny Toronto, Canada Yes, this is true. I have seen this. It occurs when you are doing multiple inheritance, I have not seen it otherwise. Let's say you have the following class structure: A | B C \ / E Now, say you have an object of type E. What you will actually have in memory is the data of type B followed by the data of type C (or reversed, depending on the order inwhich you declared them on the first line of you class declaration for class E). Say you have a pointer to an E. This pointer will actually point to the first data member of B, since B is first _in_memory_. Now, say you have a function that expects an argument of type C *. When you cast an E * to a C *, i.e. (C*)&myE, the compiler will actually add sizeof(B) bytes to the pointer, so that it is now pointing at the first member of the C data contained in E. This can make some pretty interesting casts. For example, say you want to convert a C pointer, which you know is actually an E ptr, into an A ptr. (Yes, stuff like this actually comes up!). You must go: (A *)(E *)Cptr, and not (A *)Cptr, as this will not do the correct pointer subtraction required to convert a C* into an E*. Hence, some wierd things, which you only really see in multiple inheritance. Now, as far as your question, if you don't have multiple inheritance, casting should work fine. If you do have multiple inheritance, make sure you cast through all the steps needed so the compiler can keep up with you and do the neccessary pointer adjustments. If you are really worried, or you have problems, then a "safe" way is to use virtual functions which access the data. Or, if each object is supposed to perform some specific action, you can have one vertual Do() or Execute() function, which is the same for each type of object, and you don't even need to know what type of object it actually is.