struct S
{
immutable int c = 123; // I agree with Walter, what if this is far
away from the constructor
this(int i) { c = i; }
}
struct S
{
immutable int c = 123; // This should be static, compiler issues error
// No constructor
}
would it be possible to disallow a default initializer for const /
immutable member variables and instead allow a single assignment from the
constructor?
That way you can supply the default in the constructors arguments, and
everyone can see exactly what is going on. In the cases where the
variable's value cannot be overridden you HAVE to use static with a default
initializer.
On Thu, May 16, 2013 at 8:16 AM, d coder <[email protected]> wrote:
>
> On Thu, May 16, 2013 at 11:33 AM, Lars Tandle Kyllingstad <
> [email protected]> wrote:
>
>> Are you proposing that this be allowed:
>>
>> struct S
>> {
>> immutable int c = 123;
>> this(int i) { c = i; }
>> }
>>
>> and that the compiler should report an error on the following?
>>
>> struct S
>> {
>> immutable int c = 123;
>> // No constructor
>> }
>>
>
> As I understand, he is proposing that either the first code snippet be
> allowed OR the second one should be an error.
>
> Regards
> - Puneet
>
> _______________________________________________
> dmd-beta mailing list
> [email protected]
> http://lists.puremagic.com/mailman/listinfo/dmd-beta
>
_______________________________________________
dmd-beta mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/dmd-beta