how is this considered hiding methods?
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sat Sep 22 01:27:09 PDT 2012
On 9/22/12, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> But why the compiler would now require that you do that, I
> don't know. If that's the way that thnigs currently are, it starts to become
> a bit odd that the base class functions aren't automatically available.
http://dlang.org/hijack.html
There's a good reason why, consider:
class Foo
{
void foo(int) { }
}
class Bar : Foo
{
alias super.foo foo;
void foo(double) { }
}
void main()
{
auto bar = new Bar;
bar.foo(1); // calls Foo.foo
}
Now let's say Foo is a library class and you upgrade to a new version
of the library without realizing that the base method was removed:
class Foo
{
}
class Bar : Foo
{
alias super.foo foo; // error
void foo(double) { }
}
This now becomes a compile-time error. Without using the alias which
triggers the error the literal "1" would be implicitly converted to a
double and you'd end up invoking your own 'foo' method (which is no
longer an overload).
More information about the Digitalmars-d-learn
mailing list