C++????cast??????
???????????? ???????[ 2014/4/15 15:52:20 ] ????????net ???? ???????
????C ???C-style???????????£?
????(T) expression ?? T(expression) //???????Function-style??
????????????????б??????????
????????????????????????C ??????????ú?á??????????????????????????????????class??????????ANSI-C++?????????????μ????????reinterpret_cast?? static_cast?? dynamic_cast??const_cast??????????????(class)?????????????
????1.1 reinpreter_cast
?????÷???reinpreter_cast<type-id> (expression)
????'reinterpret_cast'?????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????κ??????????????
???????????????????????????????????????????????????κε?????????????????????????????????????????????????????????Ч???????
????int n=9;
????int *pt = &n; // pt = 0x002df75c
????pt = reinterpret_cast<int *> (n); // pt = 0x00000009
?????±???????????????????????????????????
class A {};
class B {};
A * a = new A;
B * b = reinterpret_cast<B *>(a);
'reinterpret_cast'???????????????????????????????????
|
????1.2 const_cast
?????÷???const_cast<type_id> (expression)
????????????????const??volatile?????????const ??volatile???????type_id??expression??????????????????????????????????????????????????????? C++ ?????????????C????????const???????????????
???????????????????????????????????????????????????????????????????????????????????????????????????????
????1.3 static_cast
?????÷???static_cast < type-id > ( expression )
?????????????expression????type-id??????????????????????????????????????????????????????????????????????????????????÷???
????1?????????????????????????????int?????char??non-const ???????? const ???????????????????C++???const_cast???????
????2????????????????????????????????????????????(type-id*)??
????3?????κ??????????????void?????
????double d = 3.14159265;
????int i = static_cast<int>(d);
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11