C++?????????????????
???????????? ???????[ 2014/10/27 11:18:53 ] ??????????????? C++
????1.1 ??????????
?????????????C?????????????????????????????????????????????????????????????????????????double?????????????int????????????£?
????double x = 3.14; int y = ??int??x;
?????????????и??????????????int *????????????int ?????????£?
????int x = 20; int *p = &x; int y = (int)p;
??????C++??????????????????????????????????????????????μ?????????????????????????
????static_cast ????????????????????????????????
????const_cast ???????????????????
????dynamic_cast ??????????£??????????????
????reinterpret_cast ?????????????????????????
????1. C++?е?static_cast??з?????????????????C?????????????????????????????????????á????磺
????int i;
????float f = 166.7f;
????i = static_cast<int>(f);
????????????i????166??
????2. C++?е?reinterpret_cast???????????????????????????????????ν“????????????λ????????????????”????????????????????????????????????磺
????int i;
????char *p = "This is a example.";
????i = reinterpret_cast<int>(p);
????????????i??p??????????????reinterpret_cast??????????????p???????????λ??????????????????????????i??//i ????????????????????????????????????????λ?????
???????????????????“???·???”
????3. dynamic_cast??????????μ????????????????????????????????????????????
?????????μ??????????????dynamic_cast??static_cast??Ч??????????
???????????????????dynamic_cast?????????????????static_cast???????
class B{
public:
int m_iNum;
virtual void foo();
};
class D:public B{
public:
char *m_szName[100];
};
void func(B *pb)
{
D *pd1 = static_cast<D *>(pb);
D *pd2 = dynamic_cast<D *>(pb);
}
????????????????У????pb??????D????????pd1??pd2?????????????????????????D??????κβ????????????
????????????pb?????????B???????????pd1??????????????????????????D????????????????????????m_szName??????pd2????????????
??????
???·???
??????????????????
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