PRODUCT : Borland C++ NUMBER : 1014 VERSION : 3.0 OS : ALL DATE : October 19, 1993 PAGE : 1/2 TITLE : Casting a base pointer to a derived pointer. As pointed out in 'The C++ Programming Language' ( Bjarne Stroustrup - Second Edition ), "...A pointer to a Class B may be explicitly converted to a pointer to a Class D that has B has a direct or indirect base class if an unambiguous conversion from D to B exists and if B is not a virtual base class. Such a case from a base to a derived class assumes that the object of the base class is a sub-object of an object of the derived class; the resulting pointer points to the enclosing object of the derived class..." It must be noted that the compiler does *not* and will *not* ensure that the subject pointer refers to an object suitably aligned in storage: this is the programmer's responsibility! In other words, the cast is only valid if the pointer was originally of the derived type. The following program shows a cast from a pointer to Object to a pointer to the derived class String. The conversion operator ( const char * ) in String class is used to confirm the success of the cast. #include #include Array A(2); int main( void ) { String *str1 = new String( "one" ); String *str2 = new String( "two" ); String *Sptr; A.add(*str1); A.add(*str2); Sptr = (String *)(&(A[1])); // Cast (Object*) to String* cout << Sptr->operator const char *() << endl; return( 0 ); } DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that PRODUCT : Borland C++ NUMBER : 1014 VERSION : 3.0 OS : ALL DATE : October 19, 1993 PAGE : 2/2 TITLE : Casting a base pointer to a derived pointer. you received with the Borland product to which this information pertains.