On Fri, 27 Mar 2009 15:13:16 -0400, Denis Koroskin <[email protected]>
wrote:
On Fri, 27 Mar 2009 21:56:36 +0300, Steven Schveighoffer
<[email protected]> wrote:
On Fri, 27 Mar 2009 13:44:48 -0400, Nick Sabalausky <[email protected]> wrote:
"Simen Kjaeraas" <[email protected]> wrote in message
news:[email protected]...
I feel the problem here is that you can access a type's static members
through an instance of it, not so much the property syntax.
That didn't even occur to me. That's certainly a problem too.
Yes, that was my main beef with the compiler when I had to fix it. I'd
prefer static member functions not be callable on instances. On the
other
hand, accessing static members is sometimes convenient:
ReallyReallyLongStructName n;
n = n.init;
int x = 5;
writefln(x.init); // prints 0; how is that possible?
Because init is a static member of the type. x.init is equivalent to
int.init.
If you want a different default, I think you do something like:
typedef int myint = 5;
myint x;
writefln(x.init); // prints 5
It should certainly be either disallowed or yield 5.
int x = 5;
writefln(typeof(x).init); // 0 as expected
Now this one is fine.
yeah, that works, but I don't like it as much. I suppose it wouldn't be
horrible to use typeof(x) everywhere you need static data, but it does
make things much nicer, especially when you have things like enums or
constants to just access them.
-Steve