#
An additional access check beyond those described earlier in [class.access] is applied when a non-static data member or non-static member function is a protected member of its designating class ([class.access.base]) and is not designated by a splice-expression.93
As described earlier, access to a protected member is granted because the reference occurs in a friend or direct member of some class C.
If the access is to form a pointer to member ([expr.unary.op]), the nested-name-specifier shall designate C or a class derived from C.
Otherwise, if the access involves a (possibly implicit) object expression ([expr.prim.id.general], [expr.ref]), the class of the object expression shall be C or a class derived from C.
[Example 1: class B { protected: int i; static int j; }; class D1 : public B { }; class D2 : public B { friend void fr(B*,D1*,D2*); void mem(B*,D1*); }; void fr(B* pb, D1* p1, D2* p2) { pb->i = 1; / error p1->i = 2; / error p2->i = 3; / OK (access through a D2) p2->B::i = 4; / OK (access through a D2, even though designating class is B) int B::* pmi_B = &B::i; / error int B::* pmi_B2 = &D2::i; / OK (type of &D2​::​i is int B​::​*) B::j = 5; / error: not a friend of designating class B D2::j = 6; / OK (because refers to static member) } void D2::mem(B* pb, D1* p1) { pb->i = 1; / error p1->i = 2; / error i = 3; / OK (access through this) B::i = 4; / OK (access through this, qualification ignored) int B::* pmi_B = &B::i; / error int B::* pmi_B2 = &D2::i; / OK j = 5; / OK (because j refers to static member) B::j = 6; / OK (because B​::​j refers to static member) } void g(B* pb, D1* p1, D2* p2) { pb->i = 1; / error p1->i = 2; / error p2->i = 3; / error } — end example]
93)93)
This additional check does not apply to other members, e.g., static data members or enumerator member constants.

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant