Walter Bright wrote: > Rainer Deyke wrote: >> I like it in Python, where all variables are references. Java is >> similar to Python in this regard, although the existence of primitive >> value types complicates the situation somewhat. >> >> I don't like it in D, where reference types and value types coexist. I >> especially don't like it in templates in D, where it may not be clear if >> you're dealing with a reference type or a value type until instantiation. > > > Is C++ really better in that regard? Given a non-trivial struct or class > declaration, I'd be hard pressed to determine if it was meant to be a > value or reference type.
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. -- Rainer Deyke - [email protected]
