Method hiding [Was: Re: System programming in D]

bearophile bearophileHUGS at lycos.com
Wed Jan 4 17:36:44 PST 2012


Walter:

> What is dangerous is (in C++) the 
> ability to override a non-virtual function, and the use of non-virtual destructors.

There is something left that I'd like to see D care more about, method hiding:


class Foo {
    string name = "c1";
    static void foo() {}
}
class Bar : Foo {
    string name = "c2";
    static void foo() {} // silent method hiding
}
void main() {}


Here I'd like D to *require* the use of a "new" keyword as C# does:

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() {}

Bye,
bearophile


More information about the Digitalmars-d mailing list