baseClass is a 2d object (i.e. 2 variables), subClass is a 3d object. Global ostream 'outs' set up.
Code:
outs << "casting subClass as baseClass using subClassObject"
<< static_cast<baseClass const&>(subClassObject) << endl
<< "casting subClass as baseClass using subClassObjectPtr"
<< static_cast<baseClass const&>(*subClassObjectPtr) << endl
sCO & its pointer already declared/defined. Both classes have constructors & destructors, plus overloaded <<.
In the given example, when we get to that part, the base copy constructor is called, then after the casting bit, the destructor is called. So:
Quote:
baseClass Copy Constructor called
casting subClass as baseClass using subClassObject
data1 data2
casting subClass as baseClass using subClassObjectPtr
data1 data2
baseClass Destructor called
hopefully that makes sense. Data3 is left out by casting the object as its base class.