Topic: access decls for methods


Author: jason@cygnus.com (Jason Merrill)
Date: Thu, 27 Jan 1994 23:05:30 GMT
Raw View
In the following example, the call b.foo() can be interpreted two ways,
depending on your reading of the ARM:

1) Illegal, since A is a private base class of B and so &b cannot be
converted to an A*.
2) Legal, because of the access declaration.

It seems to me that if you take position 1, you render access decls useless
for methods.  On the other hand, if you take position 2 (as does Cfront),
you subvert checking on pointer conversions.  I at least feel that this
should be stated explicitly in the standard.

Thoughts?

class A {
  public:
    void foo ();
};

class B: private A {
  public:
    A::foo;
};

void bar () {
  B b;
  b.foo ();
}




Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Sat, 29 Jan 1994 22:23:09 GMT
Raw View
jason@cygnus.com (Jason Merrill) writes:

>In the following example, the call b.foo() can be interpreted two ways,
>depending on your reading of the ARM:
>
>1) Illegal, since A is a private base class of B and so &b cannot be
>converted to an A*.
>2) Legal, because of the access declaration.

(2) is the correct interpretation.  See the example at the bottom of page
246 in section 11.3 of the ARM.

>It seems to me that if you take position 1, you render access decls useless
>for methods.  On the other hand, if you take position 2 (as does Cfront),
>you subvert checking on pointer conversions.

No, it is still illegal to convert from a B* to an A*.

>class B: private A {
>  public:
>    A::foo;
>};

The access declaration makes A::foo public in B.
It is as if you had written

 class B : private A {
 public:
  void foo() { A::foo(); }
 };

There are no pointer conversions involved.

--
Fergus Henderson - fjh@munta.cs.mu.OZ.AU