2012-12-18 3 views
0

this 답이없는 질문이있어서 정말 당황 스럽습니다. 이 행동이 말이 되나요? 표준에 있습니까?기본 액세스의 친구가 파생

난 당신이 게시 된 링크를 읽고 이해 것과
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 
    } 
}; 

답변

1

(일부 답변도 같은 질문 here 참조), 원래의 질문의 저자는 GCC 컴파일러의 동작 (스레드 놀랐다 :이 질문입니다

childprot cprot; cprot.f1(); cprot.f2(); // (2) 

나는 MSVC 2010 코드를 시도하고이 줄은 컴파일되지 않습니다 2009, 버전의 gcc 4.0.1 오류없이 컴파일 된 스레드)에서 했나요 그것을 반면이 라인은 안됩니다 우정은 표준에 의해 예상대로 계승되지 않습니다.

+0

대단히 감사합니다. 내 gcc 4.2.4는 여전히 원래 게시물의 것과 같습니다. cpub.f1()과 p.f?()가 컴파일해서는 안되기 때문에 컴파일해야합니다. –

관련 문제