Why is operator overloading like this in D?
CloudiDust
zrc71105129 at yahoo.com.cn
Sun Dec 10 03:14:56 PST 2006
Thank you very much Daniel!
I wonder how to quote when posting?
You wrote: (I quoted it manually :)
> If you really *do* need to copy the data a structure is pointing to, my
> suggestion would be to implement "dup" member functions. It's a little
> inconvenient, but it means that you can always count on "=" just doing a
> bit copy, and not something more.
It seems that dup is not a member of Object according to the library reference,
why? Is it because not everything can be duplicated?
On the other hand, as there are many classes with which less or greater than
comparisons (even equality tests) makes no sense, why opCmp becomes a "default"?
Resulting in a requirement to make arguments of opCmp be of type Object when
overloading?
( Maybe I'm just feeling unused to test the type of objects inside the functions. :)
If not overloaded, opEquals does a bit comparison on everything, doesn't it?
And from the reference, I get: "If a struct has no opCmp() function declared for
it, attempting to compare two structs is an error."
And what does the default opCmp do with classes?
~CloudiDust
More information about the Digitalmars-d-learn
mailing list