#include <iostream> using namespace std; class Bass{}; class Derived:public Bass{}; //这里如果为protected或者是private继承的话,则无法向上构造 int main(void){ Derived d; Bass* pb = &d;//向上构造(安全的) cout << pb << ‘,‘ << &d << endl;//两个地址是一样的 //Base* pb = static_cast<Base*>(&d);静态类型转化 return 0; }
时间: 2024-10-21 15:49:48