友元关系不能继承,也就是说基类友元不能访问子类私有和保护成员
class Student;
class Person
{
public:
friend void fun(const Person
& p
, const Student
& s
);
protected:
int Ppro
= 0;
private:
int Ppri
= 1;
};
class Student :public Person
{
protected:
int Spro
= 0;
private:
int Spri
= 1;
};
void fun(const Person
& p
, const Student
& s
)
{
cout
<< p
.Ppri
<< " " << p
.Ppro
<< endl
;
cout
<< s
.Ppri
<< " " << s
.Ppro
<< endl
;
}
int main()
{
Person p
;
Student s
;
fun(p
, s
);
return 0;
}
这个知识点一般在我们的编写代码的时候是不会遇到的,作为了解就可以。
转载请注明原文地址:https://ipadbbs.8miu.com/read-42718.html