Re: How to Compare 2 objects of the same class

2017-06-03 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jun 03, 2017 at 10:38:31PM +, Mark via Digitalmars-d-learn wrote: [...] > Ok. So by using '==' it should compare the addresses of the objects? [...] No, `==` is for comparing the *contents* of the objects. You need to implement opEquals() for the objects being compared in order to

Re: How to Compare 2 objects of the same class

2017-06-03 Thread Mark via Digitalmars-d-learn
On Saturday, 3 June 2017 at 23:32:44 UTC, Ali Çehreli wrote: ... Ali Awesome, that might be handy in the near future. Thanks.

Re: How to Compare 2 objects of the same class

2017-06-03 Thread Ali Çehreli via Digitalmars-d-learn
On 06/03/2017 03:38 PM, Mark wrote: > Ok. So by using '==' it should compare the addresses of the objects? That's the default behavior. You can change it with opEquals: http://ddili.org/ders/d.en/object.html#ix_object.opEquals I think you want to use the 'is' operator:

Re: How to Compare 2 objects of the same class

2017-06-03 Thread Mark via Digitalmars-d-learn
On Saturday, 3 June 2017 at 22:52:42 UTC, Mark wrote: Thanks again. Nevermind, I got it.

Re: How to Compare 2 objects of the same class

2017-06-03 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 3 June 2017 at 22:38:31 UTC, Mark wrote: In the future I'll include a compilable example. I was having problems with a class I made which is about 45 lines, that might be a lot of code for a post. You can use external resources such as: https://d.godbolt.org/

Re: How to Compare 2 objects of the same class

2017-06-03 Thread Mark via Digitalmars-d-learn
On Saturday, 3 June 2017 at 22:38:31 UTC, Mark wrote: ... Thanks. Actually, I got another question, how Can I obtain the actual memory address of a class? I'll still need to solve the problem of taking ints/floats/reals etc., as well as structs and classes and sending them right/left in

Re: How to Compare 2 objects of the same class

2017-06-03 Thread Mark via Digitalmars-d-learn
On Saturday, 3 June 2017 at 20:24:44 UTC, ag0aep6g wrote: By default, they act the same. But you can change how `==` behaves by overriding `opEquals`. You cannot override `is`. Ok. So by using '==' it should compare the addresses of the objects? I think I didn't include the other file as

Re: How to Compare 2 objects of the same class

2017-06-03 Thread ag0aep6g via Digitalmars-d-learn
On 06/03/2017 10:02 PM, Mark wrote: auto A = new Box(); auto B = new Box(); if(A.opEquals(B)) {} gives the error test.o:(.data.rel.ro+0x18): undefined reference to `_D5Stack12__ModuleInfoZ' collect2: error: ld returned 1 exit status Error: linker exited with status 1 Your code works for

Re: How to Compare 2 objects of the same class

2017-06-03 Thread cym13 via Digitalmars-d-learn
On Saturday, 3 June 2017 at 20:02:13 UTC, Mark wrote: On Saturday, 3 June 2017 at 19:57:47 UTC, Mark wrote: Hello again. I'm designing a template version of a BST. Because of this, I want to be able to compare if two objects of the same class type are references to the same anonymous class

Re: How to Compare 2 objects of the same class

2017-06-03 Thread Basile B. via Digitalmars-d-learn
On Saturday, 3 June 2017 at 20:02:13 UTC, Mark wrote: On Saturday, 3 June 2017 at 19:57:47 UTC, Mark wrote: Hello again. I'm designing a template version of a BST. Because of this, I want to be able to compare if two objects of the same class type are references to the same anonymous class

Re: How to Compare 2 objects of the same class

2017-06-03 Thread Mark via Digitalmars-d-learn
On Saturday, 3 June 2017 at 19:57:47 UTC, Mark wrote: Hello again. I'm designing a template version of a BST. Because of this, I want to be able to compare if two objects of the same class type are references to the same anonymous class on the heap somewhere. Example: Not sure what

How to Compare 2 objects of the same class

2017-06-03 Thread Mark via Digitalmars-d-learn
Hello again. I'm designing a template version of a BST. Because of this, I want to be able to compare if two objects of the same class type are references to the same anonymous class on the heap somewhere. Example: