1
2
3
4
5
6
7
8
9
10
11
//强制转换类型
static_cast<>();
reinterpret_cast<>();


//cast关键字
const int ease = 81;
const char str[20] ="dsjaid";
cahr * ps = const_cast<char *>(str); //ps指针就可以修改str的值


父类指针转换为子类对象

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void show(Animal *base)
{
base->cry();
Cat* pc = dynamic_cast<Dog *>(base);
if(pc)
{
pc->catchMouse();
}
Dog* pd = dynamic_cast<Cat *>(bash);

if(pd)
{
pd->seeHome();
}
}