Comparing Instances of Classes

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Mar 10 08:13:21 PST 2017


On Friday, 10 March 2017 at 16:08:05 UTC, DRex wrote:
> Am I missing something here?

Yeah, you need to implement a custom equality operator.

class A {
    int member;
    override bool opEquals(const A rhs) {
         return this.member == rhs.member; // and other members 
that need to be equal
    }
}


The default opEquals sees if they are the same *instance* (same 
as `a is b`), and does not look at contents. You need to define 
that yourself.


More information about the Digitalmars-d-learn mailing list