Why can't we make reference variables?

Namespace rswhite4 at googlemail.com
Thu Aug 30 00:35:32 PDT 2012


> I had totally forgotten what it says in "The book" about struct 
> and class construction. It's basically that all fields are 
> first initialized to either T.init or by using the field's 
> initializer. That means the use of ref inside class or struct 
> would be quite restricted:
>
> int globalVal;
>
> struct MyStruct
> {
>     // ref int defaultInitRef; // Illegal: reference variables
>                                // can't be default initialized

But you can handle it like const members: you have to initialize 
these members in the ctor.


More information about the Digitalmars-d mailing list