Topic: Accessing inherited public static methods of a private base class
Author: jamshid@emx.cc.utexas.edu (Jamshid Afshar)
Date: 29 Sep 1993 16:16:42 -0500 Raw View
In article <CDrp7x.Gnn@hawnews.watson.ibm.com>,
Theodore C. Law <tedlaw@vnet.ibm.com> wrote:
>// statement on p.243 states only that: "Specifying a base
>// class private does not affect access to static members of
>// the base class." It does not seem to be strong enough. I
>// think it should say something like "Specifying a base class
>// private does not affect access to static members of the base
>// class itself and those of its bases."
>class A {
> public:
> static void f() { printf( "A::f()\n" ); }
>};
>class B : public A {};
>class C : private B {};
>class D : public C {
> public:
> void foo1() { A::f(); } // OK
> void foo2() { B::f(); } // A::f() inaccessible
>};
If a compiler gives you an error for this code, file a bug report. I
sure the ARM intends for this to be legal. Whether you have access
to a class member should not depend on the scope path. E.g.:
class B {
friend int f();
static int priv; // private static member
};
class D : private B {};
int f() { return D::priv; } // legal!
Unfortunately I can't find anything very explicit about this; the best
I can do is ARM 10: "Note that in the class-name::name notation, [...]
the notation simply specifies a class in which to *start* looking for
a name." (emphasis mine)
Also, from 5.3:
struct B { void f(); int i; };
struct D : B {};
The types of &B::f and &D::f are the same:
void (B::*)()
Jamshid Afshar
jamshid@emx.cc.utexas.edu
Author: tedlaw@vnet.ibm.com (Theodore C. Law)
Date: Wed, 22 Sep 1993 18:11:56 GMT Raw View
// I wonder why the inherited public STATIC member B::f() is
// accessible in global_function() but not in D::foo2().
//
// According to ARM section 11.2, the call to B::g() in D::foo4()
// is allowed to avoid the absurdity of a member function
// having less access than a global function. But the
// statement on p.243 states only that: "Specifying a base
// class private does not affect access to static members of
// the base class." It does not seem to be strong enough. I
// think it should say something like "Specifying a base class
// private does not affect access to static members of the base
// class itself and those of its bases."
//
// Does ANSI say anything about this?
//
// Ted Law
#include <stdio.h>
class A {
public:
static void f() { printf( "A::f()\n" ); }
};
class B : public A {
public:
static void g() { printf( "B::g()\n" ); }
};
class C : private B {
public:
void foo() { B::f(); } // OK
};
class D : public C {
public:
void foo1() { A::f(); } // OK
void foo2() { B::f(); } // A::f() inaccessible
void foo4() { B::g(); } // OK
};
void global_function()
{
A::f(); // OK
B::f(); // OK
// This shows the absurdity that ARM
// tries to avoid
}