Title
Access of protected base classes
Status
dup
Section
11.8.3 [class.access.base]
Submitter
Sam Saariste

Created on 2008-11-18.00:00:00 last changed 158 months ago

Messages

Date: 2010-04-15.00:00:00

Rationale (April, 2010):

This is a duplicate of issue 472.

Date: 2022-11-20.07:54:16

Consider the following example:

    struct B { void f(){} };
    class N : protected B { };

    struct P: N { friend int main(); };
    int main() {
          N n;
          B& b = n; // R
          b.f();
    }

This code is rendered well-formed by bullet 3 of 11.8.3 [class.access.base] paragraph 4, which says that a base class B of N is accessible at R if

  • R occurs in a member or friend of a class P derived from N, and an invented public member of B would be a private or protected member of P

This provision circumvents the additional restrictions on access to protected members found in 11.8.5 [class.protected] — main() could not call B::f() directly because the reference is not via an object of the class through which access is obtained. What is the purpose of this rule?

History
Date User Action Args
2011-04-10 00:00:00adminsetmessages: + msg3419
2011-04-10 00:00:00adminsetstatus: open -> dup
2008-11-18 00:00:00admincreate