playing around with D
Don Clugston
dac at nospam.com.au
Mon Mar 5 07:18:37 PST 2007
Lionello Lunesu wrote:
> Don Clugston wrote:
>> Carsten Scharfenberg wrote:
>>> 4.
>>>
>>> By the way: what is the difference between
>>> static const int and const int ?
>>> Both variants work in the examples above.
>>
>> I don't know what 'static const int' means. IMHO, it should be a
>> compiler error, since you're mixing storage classes (unlike C++, in D,
>> 'const' really means constant). Use 'const int' instead.
>
> "static" is ignored in the global scope.
I think that's like:
public protected private import std.stdio;
which also compiles.
And note that "const"s can have
> different values per instance:
>
> class X {
> const int member;
> this(int x) { member = x; }
> //...
> }
>
> This is still allowed. Don't ask me why, I think it's confusing.
That's not a const. It has almost nothing in common with const int,
except an unfortunate sharing of the syntax. It should be written 'final
int member'. I was deliberately ignoring that aberration.
More information about the Digitalmars-d
mailing list