【发布时间】:2011-01-09 16:56:59
【问题描述】:
如果 Derived 类是从 Base 类私有继承的,并且 Derived 类有友元函数 f(),那么从 Derived 类和 Base 类中 f() 可以访问哪些成员。
class Base {
public:
int a;
protected:
int b;
private:
int c;
};
class Derived: private Base {
void friend f() {}
public:
int d;
protected:
int e;
private:
int f;
};
我知道如果一个类是从基类私有继承的,那么派生类中的所有内容都是私有的。
但是为什么在上面的代码中,函数 f() 可以访问 a、b、d、e、f 而不能访问 c?
【问题讨论】:
标签: c++ inheritance