Why can't we define re-assignable const reference variable?
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Thu Feb 21 16:16:09 PST 2008
Janice Caron wrote:
> char[] s;
> s.length = 5;
> /* blah */
> s.length = 25;
> /* blah */
> s.length = 10;
>
> etc. In this case, the buffer will be reallocated somewhere else, and
> the original contents copied so you don't lose anything. It's exactly
> like calling realloc() in C or C++.
Well, there's one difference between what happens there and realloc();
the latter deallocates the original while D leaves the original in place
in case there are other references to it. (This is more workable in D
than C/C++ though, since if there aren't the GC will clean it up)
More information about the Digitalmars-d
mailing list