???????????????????????????????????????????????????upercasting?????????Ч?????????????????????????????????????????????downcasting??????????????????????????????????????????????????У???

 

class Base {};
class Derived : public Base {};
Base *a = new Base;
Derived *b = NULL;
b = static_cast<Derived *>(a); //???????????????????????(?????//Derived????)

???????
????1??static_cast?????????expression??const??volitale??????__unaligned?????
????2?????????????????????У?????????????????????????????????£?????????????????????????????????????????±???????
????1.4       dynamic_cast
????????????????????????????????“????????????”??????????????????????????????????е????????????????????t???????е????????????????????????????????????
????????????????????????麯?????????????????????????????????????????????static_cast???????????????????????????????????dynamic_cast????RTTI??????????????Ч??????????dynamic_cast???????????????????????????Ч???????????????鯔?????????????????????顣?????????????У????????????????????????????Ч??????????????????NULL??
???????RTTI???????????????????????????vtable????????RTTI???????????ζ??????????????麯?????????ж?????????????????????????????? ?????dynamic_cast???????????????????upercasting??????????????????????????????????????????????dynamic_cast????

 

class Base { virtual dummy() {} };
class Derived : public Base {};
class Other{} ;
Base* b1 = new Derived;
Base* b2 = new Base;
Derived* d1 = dynamic_cast<Derived *>(b1);  // succeeds
Derived* d2 = dynamic_cast<Derived *>(b2);  // fails: returns 'NULL'
//?????????????????????????????????????????????????????bad_cast??????????????
Derived d3 = dynamic_cast<Derived &>(*b1);  // succeeds
Derived d4 = dynamic_cast<Derived &>(*b2);  // fails: exception thrown

???????Base??????麯????????????????
????1.5       С??
????reinpreter_cast??????“???????”???????????const_cast????????const??volatile????????????????
????static_cast????????Χ???????????????????????????????????????????μ??????????????dynamic_cast??static_cast??Ч?????????????????????????????????????麯??????dynamic_cast?????????????????????Ч???????static_cast?????