Functions with package protection

Simon TRENY simon.treny at free.fr
Tue Jun 2 23:29:45 PDT 2009


Sorry to dig up this old post, but I still don't understand why 'package' functions cannot be virtual? Is there a good reason for this? I can't see why we can't use polymorphism on 'package' functions!

Is there way to make it virtual without making it public? (e.g. a 'virtual' keyword?)

Thanks,
Simon TRENY


Jacob Carlborg Wrote:

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




More information about the Digitalmars-d mailing list