Is this a D puzzler or a bug?
Bradley Smith
digitalmars-com at baysmith.com
Fri Mar 30 15:51:01 PDT 2007
Jarrett Billingsley wrote:
> "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.
I don't understand what you mean by "This is the way C++ does it". The
following equivalent C++ code is perfectly fine.
class A {
protected:
void method() {}
};
class B : public A {
protected:
void method() {
A::method();
}
};
To me, this indicates that D is *not* doing it the way C++ does it.
More information about the Digitalmars-d-learn
mailing list