知识点1.保护继承下,派生类对基类成员的访问规则
基类中的成员 | private成员 | public成员 | protected成员 |
---|
派生类内部 | 不可访问 | 可以访问 | 可以访问 |
派生类的对象 | 不可访问 | 不可访问 | 不可访问 |
需要注意的是:原来基类中的私有数据成员,继承后,在派生类里面该数据成员依旧是私有的数据成员,但是规定派生类是不可以访问这个私有数据成员
——————————————————————————————————————————————————————
知识点2.找出下列代码的错误
#include<iostream>
using namespace std;
class A
{
private:
int x;
public:
int z;
void setA(int i){x=i;}
void getA(){return x;}
protected:
int y;
};
class B:protected A
{
private:
int b;
protected:
int c;
public:
int a;
void setB(int i,int j,int k,int l,int m,int n)
{
x=i;
y=j;
z=k;
a=l;
b=m;
c=n;
}
};