November 10, 2013 implement abstract method requires override | ||||
|---|---|---|---|---|
| ||||
Why do abstract methods need to be implemented with override, when interfaces don't? E.g.:
class X
{
abstract void foo();
}
class Y : X
{
override void foo() {}
}
vs
interface X
{
abstract void foo();
}
class Y : X
{
void foo() {}
}
This is a bit of a problem for a design I'm doing with template/mixin magic, making it a bit less magical. If you don't want to change this, would you consider at least providing some kind of pragma / attribute to work around it? E.g.
class X
{
pragma(nooverride, foo); // this or the following
@nooverride abstract void foo(); // ugly OK, X is hidden for user
}
class Y : X
{
void foo() {}
}
Thanks! :-)
| ||||
November 10, 2013 Re: implement abstract method requires override | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Luís Marques | On Sunday, 10 November 2013 at 02:32:18 UTC, Luís Marques wrote:
> interface X
> {
> abstract void foo();
> }
>
> class Y : X
> {
> void foo() {}
> }
Ignore the abstract in the interface, it was a copy-paste bug, although it seems to make no difference.
BTW, for completeness, I'll clarify that my exact situation is a bit more roundabout:
interface I
{
void foo();
}
class X : I
{
abstract foo;
}
class Y : X
{
void foo() {}
}
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply