TITLE: finding the "beginning address" of an object PROBLEM: Allan Clarke (clarke@ses.com), 30 May 96 This pointer originally came from Scott Meyers' "More Effective C++". It is common for designs to use the value of the "this" pointer for comparisons or for looking up in a map of some sort. The implication is that object identity is synonymous with the value of "this". This can be problematic, particularly in the presence of multiple inheritance. The value of "this" can vary depending upon which methods of which class are being executed. Until recently, there was no language support for this problem. Now there is. Consider this use of dynamic_cast class X : public ... { }; X* xp = ...; void* address = dynamic_cast(xp); From the April '95 Draft Working Paper: 5.2.6 1 The result of the expression dynamic_cast(v) is the result of converting the expression v to type T. T shall be a pointer or reference to a complete class type, or "pointer to cv void". Types shall not be defined in a dynamic_cast. The dynamic_cast operator shall not cast away constness (5.2.10). 7 If T is "pointer to cv void", then the result is a pointer to the complete object (12.6.2) pointed to by v. In other words, by doing a dynamic_cast to a void*, two pointers can be compared for equality and will compare the same if they in fact point to the same object. This method of course has the usual requirements imposed on using dynamic_cast in general.