#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; }
本文出自 “12208412” 博客,请务必保留此出处http://12218412.blog.51cto.com/12208412/1867087
原文地址:http://12218412.blog.51cto.com/12208412/1867087