Say you have three classes, a base (called Base),and two classes derived from it (called Derv1 andDerv2). Base has a pure virtual function (called TypeGet()) that is defined in both Derv1 andDerv2. I then attempt to use this code:
Derv2 my_derv2;Derv1* d1pointer = (Derv1*)&my_derv2;d1pointer->TypeGet();
Is this behavior defined and legitimate?moral?
In general, you should not type-cast one pointer type to another unless the data pointed to matches. Otherwise, you will be asking for trouble.