Is this a D puzzler or a bug?

BCS ao at pathlink.com
Fri Mar 30 16:03:06 PDT 2007


Reply to Bradley,

> 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.)
> 
> Current solution:
> 
> Replacing "A.method()" with "super.method()" corrects the problem.
> 

I think the issue is that in D everything in a given module has implicit 
private access to everything else in that module. I'm not quite sure what 
you are looking for, but this distinction generally play into things that 
change when things move from one module to another.




More information about the Digitalmars-d-learn mailing list