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
}
};
From what I understood reading the link you posted (see also the same question here with some answers), the author of the original question was surprised by the behaviour of the gcc compiler (thread from 2009, gcc version 4.0.1 mentionned in the thread) which was compiling without error this line whereas it shouldn't have:
childprot cprot; cprot.f1(); cprot.f2(); // (2)
I tried your code with MSVC 2010 and this line doesn't compile, the friendship is not inherited as expected by the standard.