Why is operator overloading like this in D?

CloudiDust zrc71105129 at yahoo.com.cn
Sat Dec 9 18:54:13 PST 2006


Greetings everybody, I am a novice in the D world (as well as one in a
newsgroup), come from the realm of C++. As I am so used to the operator
overloading mechanism in C++, it's strange enough for me that the D way
differs in a few aspects, as follows:

1. The cast operator can have only one overloaded version.

Is it a way to force the programmers not to rely on type cast?

2. There is nothing like "opPreInc".

In the reference, I got the point that "Since ++e is defined to be
semantically equivalent to (e += 1), the expression ++e is rewritten as (e +=
1) ...", so what if I only intend to overload the ++e, not the += operator,
just like the way STL defined its input / forward iterators?

3. On the missing of "opAssign".

Mr.Bright (I suppose :) stressed that we do not need to overload the
assignment operator to do anything other than a bit copy. So if one struct
contains pointers or references to others, we are hit. Maybe I am so immersed
in the C++ way that I feel the way like java / C# is slightly misleading.
Could you give me some advice on how to "overcome" that?

BTW: I wonder if the scoped objects are still references, as they are "newed"?

Many thanks for your time,
  ~CloudiDust



More information about the Digitalmars-d-learn mailing list