Method hiding
bearophile
bearophileHUGS at lycos.com
Thu Jan 5 15:12:21 PST 2012
Jesse Phillips:
> > class Foo {
> > string name = "c1";
> > static void foo() {}
> > }
> > class Bar : Foo {
> > string name = "c2";
> > static void foo() {} // silent method hiding
> > }
> > void main() {}
>
> Should we just disallow this?
Sometimes it's an useful idiom, and probably some D code in the wild is using it already, so I don't think we should disallow it.
I was just asking to force it to be syntactically explicit, just like override will do in D2. It seems Delphi too does the same thing using a different keyword (this is not too much surprising, the language designers are partially the same).
So far I have seen no arguments against the requirement (initially just a warning if you compile with -w) to use a keywords as "new" there, while I have reasons for it in both my object oriented code and C# language design :-)
> If the function wasn't static it would just override foo.
> Or is that changing once override is required?
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 :-)
Bye,
bearophile
More information about the Digitalmars-d
mailing list