父类指针和子类对象
如果用父类指针指向子类对象,能否访问子类多出来的数据成员或者成员函数?(除了虚函数)
例如
class shape { public: shape(); ~shape(); }; class circle:public shape { public: circle(); ~circle(); int radius; }; shape *p = new circle; cout << p->radius << endl; //能否通过此语句访问circle的radius
如果用父类指针指向子类对象,能否访问子类多出来的数据成员或者成员函数?(除了虚函数)
例如
class shape { public: shape(); ~shape(); }; class circle:public shape { public: circle(); ~circle(); int radius; }; shape *p = new circle; cout << p->radius << endl; //能否通过此语句访问circle的radius
2018-08-23
举报