Manifest constants - why not 'alias' ?
Walter Bright
newshound1 at digitalmars.com
Thu Dec 6 21:06:15 PST 2007
Robert Fraser wrote:
> Walter Bright wrote:
>> Bill Baxter wrote:
>>> Enum is short for 'unumeration'. But manifest constants aren't
>>> enumerating anything. It makes no sense.
>>
>> Because we already use enums to declare constant values.
>>
>> enum { x = 3 }
>
> Will enum be able to work as a modifier as in:
>
> enum
> {
> int x = 3;
> auto y = "hello";
> }
>
> ...?
I seriously doubt it <g>.
> Also, unrelated, will there be a way to declare a class variable that is
> constant after construction (it is assigned once in the constructor,
> then doesn't change)?
Yes, just don't supply an initializer for it:
class C
{
const int x;
this()
{
x = 3; // ok
}
void foo()
{
x = 3; // error, x is const
}
}
More information about the Digitalmars-d
mailing list