References in D
Henning Pohl
henning at still-hidden.de
Sat Sep 15 05:39:49 PDT 2012
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). So you can be sure to have a valid
well-defined object. But then there is always the ownership
problem which renders them more dangerous as they seem to be. D
resolves this problem using a garbage collector.
So why not combine the advantages of C++ references "always
there" guarantee and D's garbage collector and make D's
references not nullable? If you want it to be nullable, you can
still make use of real pointers. Pointers can be converted to
references by implicitly do a runtime check if the pointer is not
null and references can be converted back to pointers.
I guess you had good reasons about choosing the nullable version
of D references. Explain it to me, please.
More information about the Digitalmars-d
mailing list