I came across this unanswered question and it is really puzzling. Is this behavior supposed to make any sense? Is it in the standard? This is the question:
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
}
};