Re: Overriding opEquals in classes, for comparison with things that aren't Objects

2016-01-29 Thread pineapple via Digitalmars-d-learn
On Friday, 29 January 2016 at 15:13:45 UTC, Mike Parker wrote: The first implementation is fine because you're overriding the implementation in the base class (Object). However, the second one fails because it's a template. Templates are non-virtual and cannot override anything. Even if you cou

Re: Overriding opEquals in classes, for comparison with things that aren't Objects

2016-01-29 Thread Mike Parker via Digitalmars-d-learn
On Friday, 29 January 2016 at 15:00:59 UTC, pineapple wrote: With this bit of code, the first method seems to work fine - things go as expected. But I get a compile error with the second method, and I'm not sure how else to write this. override bool opEquals(Object value) const{ re

Re: Overriding opEquals in classes, for comparison with things that aren't Objects

2016-01-29 Thread pineapple via Digitalmars-d-learn
It also occurred to me to do something like this, but it isn't accepted either. override bool opEquals(T)(T value){ return this.equals(value); }

Overriding opEquals in classes, for comparison with things that aren't Objects

2016-01-29 Thread pineapple via Digitalmars-d-learn
With this bit of code, the first method seems to work fine - things go as expected. But I get a compile error with the second method, and I'm not sure how else to write this. override bool opEquals(Object value) const{ return this.equals(cast(typeof(this)) value); } override