References in D

Walter Bright newshound2 at digitalmars.com
Sat Sep 15 16:29:32 PDT 2012


On 9/15/2012 3:42 PM, Henning Pohl wrote:
> On Saturday, 15 September 2012 at 21:30:03 UTC, Walter Bright wrote:
>> On 9/15/2012 5:39 AM, Henning Pohl wrote:
>>> The way D is dealing with classes reminds me of pointers because you can null
>>> them. C++'s references cannot (of course you can do some nasty casting).
>>
>> Doing null references in C++ is simple:
>>
>> int *p = NULL;
>> int& r = *p;
>>
>> r = 3; // crash
>
> Next time I think before I write.

I wouldn't worry about it. I suspect that most C++ programmers think that 
references cannot be null. C++ is a complex language, and invites assumptions 
about it that are not so.

Const in C++ is another one loaded with incorrect assumptions.



More information about the Digitalmars-d mailing list