Overloading the assignment operator, right now!
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Fri Sep 22 14:34:00 PDT 2006
Sean Kelly wrote:
> Georg Wrede wrote:
>> Overloading of the assignment operator is not allowed in D.
>
> Overloading the assignment operator in a language where objects are
> manipulated through references would be a bit weird, wouldn't it? It
> would almost require the creation of a new assignment operator meant
> specifically for copy semantics, similar to how we have '==' and 'is'
> for identity vs. equality comparisons.
>
>
> Sean
That might be just the right thing to do (to have a copy operator), just
as we have those two comparison operators.
One possible prominent advantage, in terms of things that Walter likes,
(but that others such as me and others don't care that much about) is:
ease of porting from C++ to D.
Whereas a 'pointer to C++ class' translates easily and directly into a
'D class', the same is not for a 'C++ class', because it is a value
type. If the C++ class doesn't use inheritance you might just get away
with porting it to a D struct, but that likely won't be the case. You
will have to make a translation that is not direct, and thus bothersome
and/or error-prone. Having such a copy operator would allow for a direct
translation, I think.
One must be wary of what Oskar mentioned: that the assignment operator
is not the only assignment, there is also the implicit assignment of a
function call's argument passing. I think this can be easily solved by
having the function call use the copy operator, if it is overloaded, for
argument creation. Hum.., now that this is mentioned, how does it work
in C++? Does C++ do it that way?
--
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d
mailing list