Old problem with performance
Christopher Wright
dhasenan at gmail.com
Thu Feb 12 06:07:21 PST 2009
Rainer Deyke wrote:
>> What mechanism for sharing state is available to by-reference objects
>> but not by-value objects?
>
> struct C {
> T t;
> }
>
> C c1;
> C c2 = c1;
>
> If T was a reference type, 'c1' and 'c2' now share state, and it's up to
> the programmer to write code to prevent this. Moreover, the D language
> doesn't even give a hint as to whether T or a reference type or a value
> type. If T is a template parameter, it could be both.
Okay, reference types don't have value semantics. That's exactly what I
would expect. Why is it a problem? Because there is no explicit builtin
copying mechanism for classes? If there were such, would it be a problem
if copying were not the default?
More information about the Digitalmars-d
mailing list