Why can't we define re-assignable const reference variable?
Sean Reque
seanthenewt at yahoo.com
Sun Feb 17 17:08:21 PST 2008
>
> Of course not. That would be impossible.
>
> You cannot have a mutable reference to const data in C++, so what's
> the big deal? The best you can achieve in C++ is a mutable /pointer/
> to const data, and that is also allowed in D.
>
This argument is completely pointless, because in C++ you don't have references at all, at least not in the same sense as references are in most every other high-level language, including D, Java, C# Perl, Python, Ruby, Smalltalk, Scheme, Javascript, etc. In most languages, including D, references are basically there to replace pointers as a much safer and more syntactically pleasing alternative when the full power of pointers isn't needed or desired (segmentation fault, anyone?). Therefore, references in D should have the same flexibility as a pointer would. But right now references behave like pointers in terms of assignment, but const references do NOT behave like const pointers in terms of assignment, and that simply should not be.
More information about the Digitalmars-d
mailing list