Re: Comparing Instances of Classes

2017-03-10 Thread DRex via Digitalmars-d-learn
On Friday, 10 March 2017 at 20:27:09 UTC, Meta wrote: On Friday, 10 March 2017 at 17:08:42 UTC, Whatsthisnow wrote: I guess i am just too used to the java way of x.equals(object) which at the source is exactly 'return this == object' Java would return false here too, though, if it actually di

Re: Comparing Instances of Classes

2017-03-10 Thread Meta via Digitalmars-d-learn
On Friday, 10 March 2017 at 17:08:42 UTC, Whatsthisnow wrote: I guess i am just too used to the java way of x.equals(object) which at the source is exactly 'return this == object' Java would return false here too, though, if it actually did `this == object` in its default compare method. If I

Re: Comparing Instances of Classes

2017-03-10 Thread Ali Çehreli via Digitalmars-d-learn
On 03/10/2017 08:22 AM, DRex wrote: Error: function app.A.opEquals does not override any function, did you mean to override 'object.Object.opEquals'? My A class appears exactly as mentioned in your comment... FWIW, here's some other info: http://ddili.org/ders/d.en/object.html#ix_object.op

Re: Comparing Instances of Classes

2017-03-10 Thread Whatsthisnow via Digitalmars-d-learn
On Friday, 10 March 2017 at 16:47:47 UTC, Adam D. Ruppe wrote: On Friday, 10 March 2017 at 16:36:17 UTC, DRex wrote: I'm fairly new to D, but this seems to be quite a pain in the rear for a simple comparison of instances of classes...really odd that comparing instances of classes in D requires

Re: Comparing Instances of Classes

2017-03-10 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 10 March 2017 at 16:36:17 UTC, DRex wrote: I'm fairly new to D, but this seems to be quite a pain in the rear for a simple comparison of instances of classes...really odd that comparing instances of classes in D requires that messing around when D seems all about simplifying things..

Re: Comparing Instances of Classes

2017-03-10 Thread DRex via Digitalmars-d-learn
On Friday, 10 March 2017 at 16:30:00 UTC, Adam D. Ruppe wrote: On Friday, 10 March 2017 at 16:22:18 UTC, DRex wrote: Error: function app.A.opEquals does not override any function, did you mean to override 'object.Object.opEquals'? Oh sorry, maybe I messed up the const. Try: override bool opEq

Re: Comparing Instances of Classes

2017-03-10 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 10 March 2017 at 16:22:18 UTC, DRex wrote: Error: function app.A.opEquals does not override any function, did you mean to override 'object.Object.opEquals'? Oh sorry, maybe I messed up the const. Try: override bool opEquals(A rhs) { ... } and if the compiler still complains change

Re: Comparing Instances of Classes

2017-03-10 Thread DRex via Digitalmars-d-learn
On Friday, 10 March 2017 at 16:13:21 UTC, Adam D. Ruppe wrote: 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.membe

Re: Comparing Instances of Classes

2017-03-10 Thread Adam D. Ruppe via Digitalmars-d-learn
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