Reddit: why aren't people using D?
Walter Bright
newshound1 at digitalmars.com
Fri Jul 24 11:39:29 PDT 2009
Rainer Deyke wrote:
> Yes, it is. Mainly because C++ doesn't have reference types in same way
> that D does.
>
> In C++, values of *all* types (including primitive integral types and
> even pointer types) can be placed on the heap, and such values are
> *always* managed by (smart) pointers, with pointer syntax. In this
> sense, all types in C++ can be used as reference types.
>
> There are C++ classes that are meant to always be placed on the heap and
> managed by a pointer. They are the closest C++ has to D-style classes.
> They are exceedingly rare. They're also easy to identify: their
> constructors are protected, so the only way to instantiate them is by
> calling a factory function that returns a (smart) pointer.
A reference type isn't defined as one that only exists on the heap. Even
in D, value types can be in the heap, and reference types can be on the
stack.
The value/reference dichotomy is how the object is referred to, not
where it is.
More information about the Digitalmars-d
mailing list