Is this a D puzzler or a bug?

Bradley Smith digitalmars-com at baysmith.com
Fri Mar 30 17:42:50 PDT 2007


BCS wrote:
> 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.
> 

I was looking for a way to call a specific superclass method from an 
overridden method. I wasn't expecting that access to a non-static method 
through a static call would have different protection than specified on 
the non-static method.


More information about the Digitalmars-d-learn mailing list