Overloading static methods
bearophile
bearophileHUGS at lycos.com
Mon Aug 29 11:09:49 PDT 2011
Jonathan M Davis:
> Yeah. I don't know why it's allowed. I think that C++, Java, and C# all allow
> it too, but I've always thought that it was a bad idea in all of those
> languages.
> ...
> but it strikes me as very lax to allow a static
> method to be called with an instance. That's definitely one of the little
> things that I'd love to see changed.
I agree. I don't understand the rationale for allowing the access of static fields though the instance name. Requiring the class/struct name also makes the look of this code more meaningful:
const struct Foo {
int x;
static int y;
static void incy() { y++; }
}
void main() {
Foo f = Foo(5);
f.y++; // no error here
f.incy(); // no error here
}
Bye,
bearophile
More information about the Digitalmars-d
mailing list