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

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

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:

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
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 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

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

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

Comparing Instances of Classes

2017-03-10 Thread DRex via Digitalmars-d-learn
Hi, I am trying to compare two instances of a class. I created a test program to try this, but every method I use to compare the instances always returns false. this is my code to test comparison class A { this() { } } void main() { A a = new A(); A a2 = new A();