继承中的特殊关系隐藏

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
using namespace std;
class person
{
protected:
int age;
public:
void print()
{cout<<age<<endl;}
/* person()
{age=18;}
*/


};
class worker:public person
{
private:
int age;
public:
void print()
{cout<<age<<endl;}
worker()
{age=20;person::age=18;}
};
void main()
{
worker A;
A.print();//调用类子类函数
A.person::print();//调用父类函数
}