Why can't we define re-assignable const reference variable?
Christopher Wright
dhasenan at gmail.com
Sat Feb 16 14:37:58 PST 2008
Janice Caron wrote:
> On 16/02/2008, Christopher Wright <dhasenan at gmail.com> wrote:
>>>> What's the difference (save polymorphism) between a pointer to a struct
>>>> and a reference to an object?
>> In C++, there's no difference between the two.
>
> Yes there is.
>
> S * p = whatever;
> S & r = whatever;
>
> p can be rebound. r can't.
Hm. Perhaps I should learn c++ before talking about it.
>> I've never heard any explanation of how reassignable const objects would
>> break the type system,
>
> Because you'd need a brand new syntax to do it, and whatever syntax
> you chose, it would break generic programming.
generic programming != type system
I forgot about that argument, though. Thanks for reminding me. The
solution, of course, is first-class references for everything, which
Walter isn't willing to do. In almost every circumstance, it'd be
duplicated functionality.
More information about the Digitalmars-d
mailing list