aliasing base methods
Bill Baxter
dnewsgroup at billbaxter.com
Sun Feb 25 11:03:00 PST 2007
Frank Benoit (keinfarbton) wrote:
>> class Base
>> {
>> int foo(int) { ... }
>> }
>> class Derived : Base
>> {
>> // Is this "error: override keyword required"
>> // Or is it ok -- not an override but a distict overload leaving
>> // foo(int) in tact.
>> int foo(float) { ... }
>> }
>>
>
> In this case it would compile without error. You did not provide
> 'override', so you say: make overload.
>
> If 'override' is required, it would be obvious, that it is missing.
I'm not so sure. I try to live by the 'mark all overrides' policy
myself but still I often forget.
> So I
> think it would be much easier to find this error (if override was
> meant). And it is documented for a later reader. This is an improvement
> of readability.
Any improvement of readability comes from 2) -- making 'override'
required. Not from 1) -- making all overloads propagate. 1) saves
typing but does not necessarily improve readability. What could be more
clear than an explicit list of all the base class versions of foo()?
Also -- does this() get special treatment? Or do constructors all
automatically propagate too?
And in general how do I hide super.foo(int) if I _don't_ want it?
(private assert(0) re-implementation of every method I don't want perhaps?)
I guess I would be happier with something that required explicitly
declaring that base class overloads should be forwarded. Like
alias super.foo foo; // bring forward all base class foo's
or
alias super.foo(int) foo; // bring forward only the int version.
Another thought -- making override required could make life difficult
for some code generators. Imagine an automatic class wrapper that
creates a derived class of the form:
class foo(Base) : Base
{
int someMethod(int x) { ... }
}
That will always work now, but if override becomes required, then that
template will have to do some static if mojo to figure out if Base
already has a someMethod(int) implemented or not and if so stick in the
'override'.
--bb
More information about the Digitalmars-d
mailing list