#include<iostream>
using namespace std;
class A
{
protected:
int m;
};
class B: public A
{
public:
void show()
{
m=10;
cout<<"m is :"<<m<<endl;
}
};
void main()
{
B p;
// p.m= 10; 这个会报错,因为m在A中是protected型,然后在派生类中会变成private,因此在类外是不可以访问
p.show();
}
如上代码所示,在基类中为protected类型,在子类中会变成private类型,类外无法访问。