Taking a copy of an object

Mikola Lysenko mclysenk at mtu.edu
Thu Aug 10 07:46:30 PDT 2006


On Thu, 10 Aug 2006 16:36:04 +1000, Derek Parnell wrote:
>
> The only problem is the phrase "If everyone adheres to this convention".
> That will never happen, people being as they are. This is why I'd like
> these capabilities to be supported by the compiler via the use of operators
> that invoke the associated 'op' function.

The problem is that a new operator doesn't really solve anything.  There
is no way for the compiler to strictly enforce that 'opClone' performs a
clone, much as it can not check that 'opAdd' performs an addition.  Adding
new operators is hardly a guarantee that programmers will use them
sensibly, and it seems unnecessary given the current property syntax is
equivalent.

A convention might seem a bit weak, but it has worked successfully in the
past.  Consider C++'s copy constructor and operator= ; neither have any
guarantee that they will act as intended.  It is the responsibility of the
programmer alone to ensure they are correct.  However, it is not very
difficult to correctly implement and verify these sorts of methods, it
should not create much of a burden.




More information about the Digitalmars-d mailing list