Is this a D puzzler or a bug?

Jarrett Billingsley kb3ctd2 at yahoo.com
Fri Mar 30 15:11:00 PDT 2007


"Bradley Smith" <digitalmars-com at baysmith.com> wrote in message 
news:eujsku$2njp$1 at digitalmars.com...
> What is wrong with the following code?
>
> class A {
>   protected void method() {}
> }
>
> class B : public A {
>   protected void method() {
>     A.method();
>   }
> }
>
> Answer:
>
> If A and B are defined in the same module, A is able to access the 
> non-static protected method of its superclass using a static method call.
>
> However, if A and B are defined in different modules, the error "class a.A 
> member method is not accessible" occurs.
>
> Is this a bug? (I don't know. I am really asking.)
>

This is "the way C++ does it" and therefore the way D should do it as well. 
It also means that B can't access any protected members of A references. 
Stupid, I know, and it's never going to change as long as Walter is in 
charge.

> Current solution:
>
> Replacing "A.method()" with "super.method()" corrects the problem.

That's really how you're "supposed" to do it.  It's also a little 
nicer-looking, since it's obvious you're calling the base class's 
implementation of the method. 




More information about the Digitalmars-d-learn mailing list