Comment #0 by bearophile_hugs — 2012-01-09T12:50:54Z
I'd like to see D care more about this, method hiding:
class Foo {
string name = "c1";
static void foo() {}
}
class Bar : Foo {
string name = "c2";
static void foo() {} // silent method hiding
}
void main() {}
In such situations I'd like D to require the use of a "new" keyword as C# does (as with 'override', it first becomes a warning):
class Foo {
string name = "c1";
static void foo() {}
}
class Bar : Foo {
string name = "c2";
static new void foo() {} // method hiding is now visible
}
void main() {}
The point here is to make the purpose and meaning of the code more explicit.
---------------------
See also an answer by Jesse Phillips:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=154448
>> Override usage is going to be (hopefully soon) compulsory in D
>> (currently you need -w to see an error). So that code without
>> both static and override is going to be refused :-)
>
> I guess the question I was getting at, currently there is no way
> to "hide" a non-static member function like you would do in C#
> with 'new.' Is that intended once 'override' is required? and if
> not why have 'new' usable for static methods?
Comment #1 by alex — 2012-01-09T12:52:24Z
I completely agree. If we have mandatory override, we should have this as well.
Comment #2 by bearophile_hugs — 2012-01-14T10:26:48Z