static_cast可以将任意类型的指针转换为void*,并且将void*指针转换回原始类型的指针。 static_cast可以将子类指针转换为父类指针,但不能将父类指针转换为子类指针。 static_cast不会进行运行时类型检查,因此在进行指针类型转换时需要确保转换是合法的,否则可能导致未定义的行为。 0 赞 0 踩最新问答Debian系统安全漏洞...
1.static_cast基本类型转换 intmain1() {//printf("%d", 10.2);//printf("%f", (float)1);//printf不会完成数据类型转换//printf("%d", static_cast<int>(10.2));//默认转换printf("%f", static_cast<float>(1)); } 2.reinterpret_cast(指针类型转换) ...
static_cast静态类型转换指针导致崩溃报错 核心代码如下: typedefstructA1 {charpos[4]; }A; typedefstructB1 {charzoom[4];charpos[8]; } B;intmain() { A* a1 =newA;B* b1 = static_cast<B*>a1;for(inti =0; i <8; ++i) { b1->pos[i] =0; } }...