#include"inherit_02.h"
class Base
{
public:
int a;
protected:
int b;
private:
int c;
};
// 公共继承
class ChildrenA :public Base
{
void writer()
{
a = 10;// 公共权限
b = 10;// 保护权限
//c = 10;// c是私有函数所以无法赋值
}
};
//保护继承
class ChildrenB :protected Base
{
void writer()
{
a = 10;// 保护权限可赋值
b = 10;// 保护权限可赋值
//c = 10;// c是私有函数所以无法赋值
}
};
// 私有继承
class ChildrenC :private Base
{
void writer()
{
a = 10;// 私有权限可赋值
b = 10;// 私有权限可赋值
//c = 10;// c是私有函数所以无法赋值
}
};
void inherit_02_test_01()
{
ChildrenA mai;
cout << mai.a << endl;//可访问
//cout << mai.b << endl;// 不可访问子类的保护权限成员
//cout << mai.c << endl;// 不可访问子类的私有权限成员
ChildrenB song;
//cout << song.a << endl;//不可访问子类的保护权限成员
//cout << song.b << endl;//不可访问子类的保护权限成员
//cout << song.c << endl;//不可访问子类的私有权限成员
ChildrenB lee;
//cout << lee.a << endl;//不可访问子类的私有权限成员
//cout << lee.b << endl;//不可访问子类的私有权限成员
//cout << lee.c << endl;//不可访问子类的私有权限成员
}