cannot modify struct with immutable members

ted via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 2 18:55:31 PST 2015


I get the following error from the code below: (dmd2.066.1, linux)
test.d(26): Error: cannot modify struct myTest1 Test with immutable members

Is this expected?

If so, how can I achieve this result - being able to set (a new) initial value 
of myTest1 from within an nested function ?

thanks !
ted


code: 
struct A
{
    int someInt;
}

struct Test
{
    this( ref const(A) arg )
    {
        mA = arg;
    }

private:
    const(A) mA;
}

void main()
{
    Test myTest1;
    A topA;

    void _someFunc( ref const(A) myA )
    {
        myTest1 = Test(myA);
    }

    Test myTest2 = Test(topA);      // is ok as expected
    _someFunc( topA );		  // error.
}


More information about the Digitalmars-d-learn mailing list