SmartPhone sp (10000, 800, "android");
Phone* pp = &sp;
Camara* pc = &sp;
Computer* po = &sp;
printf ("%p,%p,%p,%p\n", &sp, pp, pc, po);
pp = reinterpret_cast<Phone*> (&sp);
pc = reinterpret_cast<Camara*> (&sp);
po = reinterpret_cast<Computer*> (&sp);
printf ("%p,%p,%p,%p\n", &sp, pp, pc, po);(SmartPhone 继承Phone,Camara,Computer)
为什么这里,
Phone* pp = &sp;
Camara* pc = &sp;
Computer* po = &sp;
printf ("%p,%p,%p,%p\n", &sp, pp, pc, po);
pp,
pc
po
的地址不一样
下面强制类型转换之后就一样了?
C++不像c#是引用的类型,
Phone* pp = &sp;
Camara* pc = &sp;
Computer* po = &sp;
这3个就会分配不同的空间了。