How do you overload opEquals?
Dale Matthews
dem7w2 at mst.edu
Tue Nov 19 13:25:46 PST 2013
On Tuesday, 19 November 2013 at 21:10:57 UTC, Chris
Nicholson-Sauls wrote:
> override bool opEquals (Object o) const {
> if ( auto v = cast( typeof( this ) ) o )
> return x == v.x && y == v.y && z == v.z;
> return false;
> }
>
>
> You need:
> 1) 'override' in order to override the base class
> implementation.
> 2) 'Object' typed parameter, then cast.
Very cool, it works great! Thanks for the help, Chris.
Adam, do you recommend using a struct instead of a class? I'm
from C++ where structs are mainly used for PODs. It sounds handy
in instances like this though:
http://dlang.org/cpptod.html#structcmp
More information about the Digitalmars-d-learn
mailing list