Functions with package protection
Jacob Carlborg
doobnet at gmail.com
Sat Jun 21 06:47:01 PDT 2008
Frank Benoit wrote:
> Jacob Carlborg schrieb:
>> In the D documentation at
>> http://www.digitalmars.com/d/1.0/function.html it says the following:
>> "All non-static non-private non-template member functions are
>> virtual", but this seems not to be the case. What I've heard and as
>> the following example shows functions declared as package are
>> non-virtual.
>>
>> module main;
>>
>> import tango.io.Stdout;
>>
>> class A
>> {
>> package void foo ()
>> {
>> Stdout("A").newline;
>> }
>> }
>>
>> class B : A
>> {
>> package void foo ()
>> {
>> Stdout("B").newline;
>> }
>> }
>>
>> void main ()
>> {
>> A a = new B;
>> a.foo;
>> }
>>
>> This will print "A", but according to the documentation package is
>> virtual and therefore this should print "B" but doesn't. Either the
>> documentation is wrong or the compiler.
>>
>> Compiled with GDC on OSX, I think it will give the same result with
>> dmd also.
>
> Unfortunately on
> http://www.digitalmars.com/d/1.0/attribute.html#ProtectionAttribute
> it is said:
> "Package extends private so that package members can be accessed from
> code in other modules that are in the same package. This applies to the
> innermost package only, if a module is in nested packages."
Yeah, but the documentation is still wrong. It's very annoying when the
documentation is inconsistence, incomplete or just wrong. I can see why
users unfamiliar with D have problems.
More information about the Digitalmars-d
mailing list