Why can't we make reference variables?
Mehrdad
wfunction at hotmail.com
Wed Aug 29 12:46:23 PDT 2012
On Wednesday, 29 August 2012 at 15:49:26 UTC, Namespace wrote:
>> *References cannot be null, whereas pointers can; every
>> reference refers to some object, although it may or may not be
>> valid. Note that for this reason, containers of references are
>> not allowed.
>>
>> * References cannot be uninitialized. Because it is impossible
>> to reinitialize a reference, they must be initialized as soon
>> as they are created. In particular, local and global variables
>> must be initialized where they are defined, and references
>> which are data members of class instances must be initialized
>> in the initializer list of the class's constructor. For
>> example:
>> int& k; // compiler will complain: error: `k' declared as
>> reference but not initialized
>
> That would be a dream: not null references. I'm still think
> that D needs something like that. And I'm not talking about of
> some struct constructs like NotNullable, which will be added in
> std.typecons later. I'm talking about built-in support.
+1
More information about the Digitalmars-d
mailing list