-
private和protected在继承中显示出各自特色查看全部
-
class Children : virtual public Person { public: Children(int age) { m_iAge = age; cout << "Children" << endl; } ~Children() { cout << "~Children" << endl; } void play() { cout << m_iAge << endl; cout << "play" << endl; } protected: int m_iAge; }; /** * 定义童工类:ChildLabourer * 公有继承工人类和儿童类 */ class ChildLabourer:public Worker,public Children { public: ChildLabourer(string name, int age):Worker("name"), Children(8) { cout << "ChildLabourer" << endl; } ~ChildLabourer() { cout << "~ChildLabourer" << endl; } }; int main(void) { // 用new关键字实例化童工类对象 ChildLabourer *p=new ChildLabourer("jim",8); // 调用童工类对象各方法。 p->eat(); p->work(); p->play(); delete p; p = NULL; return 0; }查看全部
-
解决重定义的技巧查看全部
-
隐藏: 实例化对象调用子类中的成员函数soldier.play(); 实例化对象调用父类中的成员函数soldier.Person::play(); 实例化对象调用子类中的数据成员code = 1234; 实例化对象调用父类中的数据成员Person::code = 1234;查看全部
-
隐藏特性,类似就近原则查看全部
-
私有继承总结查看全部
-
保护继承总结查看全部
-
公有继承总结查看全部
-
protected继承查看全部
-
public继承下访问权限表查看全部
-
1. person全部属性公有,worker公有继承,用堆实例化 2. person全部属性公有,worker公有继承,用栈实例化查看全部
-
private类外不能访问,不能继承 protected类外不能访问,可以被继承 public类外可以访问,可以被继承查看全部
-
private继承方式查看全部
-
protected继承方式查看全部
-
public继承方式:查看全部
举报
0/150
提交
取消