Why can't we define re-assignable const reference variable?

Sean Reque seanthenewt at yahoo.com
Mon Feb 18 06:46:24 PST 2008


> So why can't we have both (just as in C++):
> 
> ========================
> const B b;  // b cannot be re-bind, and the object cannot be modified
> B const b;  // b can    be re-bind, but the object cannot be modified
> ========================

The saddest part of this is it actually worked this way at least up through 2.007. I compiled the following code in a 2.007 compiler and when it worked, thought that everyone was crazy. Then I downloaded the 2.010 compiler and it wouldn't compile. So it's not even a matter of it being a lot of work to make it happen. I think everyone who is interested in having const work the older way should make keep making themselves heard!

import std.stdio;

class C {
}

int main() {
	C c1 = new C();
	C c2 = new C();
	const(C) cc = c1;
	cc = c2; 		// compiles with 2.007, but not 2.010
	writeln("done!");
	return 0;
}




More information about the Digitalmars-d mailing list