February 06, 2007 'override' question | ||||
|---|---|---|---|---|
| ||||
given a base class with method write():
# protected uint write() {printf("base\n");}
#
# void func()
# {
# write ();
# }
#
And subclass Sub with method write():
# private override uint write() {printf("sub\n");}
What should happen (a) at compile time, and (b) at runtime when invoking Sub.func?
| ||||
February 06, 2007 Re: 'override' question | ||||
|---|---|---|---|---|
| ||||
Posted in reply to kris | kris wrote:
> given a base class with method write():
>
> # protected uint write() {printf("base\n");}
> #
> # void func()
> # {
> # write ();
> # }
> #
>
> And subclass Sub with method write():
>
> # private override uint write() {printf("sub\n");}
>
>
> What should happen (a) at compile time, and (b) at runtime when invoking Sub.func?
Good question :-) I'd say it should print "base" but a subclass of Sub gets another chance to override write() since it can't see Sub.write(). It would make more sense if it were an error to have a private override method.
Sean
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply