February 18, 2008 Re: Why can't we define re-assignable const reference variable? | ||||
|---|---|---|---|---|
| ||||
> 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;
}
| ||||
February 19, 2008 Re: Why can't we define re-assignable const reference variable? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Sean Reque | "Sean Reque" <seanthenewt@yahoo.com> wrote in message news:fpc5o0$2djh$1@digitalmars.com... >> 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; > } When the latest const system became final, I was a little disappointed, but I was like "whatever". This stuff has been debated way too much and frankly I'm sick of hearing about it. Although I don't think it's going to change anything, I agree with you. Without this feature (whatever the syntax used to express it) the const system is simply incomplete. -Craig | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply