#include <iostream>
using namespace std;
class A
{
friend class C; //并不是成员
public:
int pub;
private:
int priv;
protected:
int prot;
};
class B : public A
{
B()
{
pub = 1;
// priv = 1; can not access
prot = 1;
}
};
class C // A的友元
{
C()
{
A a;
a.pub = 1;
a.prot = 2; // 可以访问protected
a.priv = 2; // 可以访问private
}
};
int main()
{
A example;
example.pub = 2;
// example.prot example.priv can not access
}