Associative Array of Const Objects?

bitwise via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Mar 29 11:43:31 PDT 2015


I'm a little confused at this point why this doesn't work either:

const(Test) test = new Test();  // fine
test = new Test();                     // error


In C++, There is a clear distinction:

const Test *test1 = nullptr; // const before type
test1 = new Test();      // fine
	
Test *const test2 = nullptr; // const before identifier
test2 = new Test();      // error: test2 is readonly

Isn't there such a distinction in D?


I would have suggested that I got things backward, but this 
doesn't work either:

const Test test = new Test();
test = new Test(); // error: cannot modify const expression


More information about the Digitalmars-d-learn mailing list