我遇到了这个悬而未决的问题,这真的很令人费解。这种行为应该有意义吗?它在标准中吗?这是问题:
class parentFriend;
class parent
{
friend class parentFriend;
public: void f1(){};
protected: void f2(){};
private: void f3(){};
};
class childpub: public parent {};
class childprot: protected parent {};
class childprv: private parent {};
class parentFriend
{
public:
void f()
{
/* which of the following statements will compile? why? why not?*/
parent p; p.f1(); p.f2(); p.f3(); // these will compile
childpub cpub; cpub.f1(); cpub.f2(); cpub.f3();
childprot cprot; cprot.f1(); cprot.f2();
cprot.f3(); // does not compile
childprv cprv;
cprv.f1(); // does not compile
cprv.f2(); // does not compile
cprv.f3(); // does not compile
}
};