Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
フレンド クラスは、フレンド関数を含むクラスのメンバーにアクセスできます。その逆、つまり、クラスはそのフレンド クラスのメンバーにもアクセスできますか?
その逆、つまり、クラスはそのフレンド クラスのメンバーにもアクセスできますか?
いいえ、できません。friendキーワードは一方向です。
friend
friend双方向の方法で機能を提供するには、両方のクラスfriendを相互に指定する必要があります。実際には、これらの候補クラスの少なくとも 1 つの前方宣言が必要です。
class B; // Forward declare class A { friend class B; }; class B { friend class A; };