override and package

Namespace rswhite4 at googlemail.com
Thu Sep 12 04:34:36 PDT 2013


On Thursday, 12 September 2013 at 11:29:22 UTC, Jacob Carlborg 
wrote:
> On 2013-09-12 11:28, Namespace wrote:
>
>> But if I try to write 'override' before [1], I get this error 
>> message:
>> Error: function T4._apply cannot override a non-virtual 
>> function
>>
>> This seems inconsistent. I really overwrite the method, and 
>> then I put
>> it in a package label.
>
> I think the error message is pretty clear. You cannot override 
> a function that isn't virtual. Private and package methods are 
> not virtual. Example:
>
> class Base
> {
>     void foo ()
>     {
>         writeln("Base.foo");
>     }
> }
>
> class Sub : Base
> {
>     package void foo ()
>     {
>         writeln("Sub.foo");
>     }
> }
>
> void main ()
> {
>     auto sub = new Sub;
>     sub.foo(); // prints "Sub.foo" as expected
>
>     Base base = sub;
>     base.foo(); // prints "Base.foo"
> }

Obvious. But what happend? Is the original _apply hidden?


More information about the Digitalmars-d-learn mailing list