Functions with package protection

Frank Benoit keinfarbton at googlemail.com
Fri Jun 20 09:06:26 PDT 2008


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."



More information about the Digitalmars-d mailing list