Re: Beginner problem: casting in opCmp override

2013-07-09 Thread H. S. Teoh
On Mon, Jul 08, 2013 at 05:09:14PM -0700, Jonathan M Davis wrote: On Monday, July 08, 2013 16:58:03 H. S. Teoh wrote: On Mon, Jul 08, 2013 at 04:48:05PM -0700, Jonathan M Davis wrote: On Monday, July 08, 2013 16:38:16 H. S. Teoh wrote: [...] Basically, when you write x==y, the

Beginner problem: casting in opCmp override

2013-07-08 Thread Ugbar Ikenaki
I'm trying to implement rational numbers with fully functioning comparison operators, but I can't seem to figure out why I'm getting this error and any help would be appreciated: Error: cannot cast from object.Object to Rat The code I have is as follows: int opCmp( Object o ) { Rat

Re: Beginner problem: casting in opCmp override

2013-07-08 Thread Jonathan M Davis
On Monday, July 08, 2013 23:21:59 Ugbar Ikenaki wrote: I'm trying to implement rational numbers with fully functioning comparison operators, but I can't seem to figure out why I'm getting this error and any help would be appreciated: Error: cannot cast from object.Object to Rat The code I

Re: Beginner problem: casting in opCmp override

2013-07-08 Thread Ugbar Ikenaki
Also…Rat is a struct, not a class. Herein might lie the problem.

Re: Beginner problem: casting in opCmp override

2013-07-08 Thread Ugbar Ikenaki
Thanks for the quick response! Here is the initialization code for my Rat struct. I created a GCD function that I've tested to work fine: import std.stdio, std.exception; struct Rat { private long n; //Numerator private long d; //Denominator

Re: Beginner problem: casting in opCmp override

2013-07-08 Thread Jonathan M Davis
On Monday, July 08, 2013 23:31:14 Ugbar Ikenaki wrote: Also…Rat is a struct, not a class. Herein might lie the problem. So, this is Rat's opCmp, correct? If it's a struct, it makes no sense for it to take an Object. Object is the base class for all classes and has nothing to do with structs.

Re: Beginner problem: casting in opCmp override

2013-07-08 Thread Ali Çehreli
On 07/08/2013 02:21 PM, Ugbar Ikenaki wrote: I'm trying to implement rational numbers with fully functioning comparison operators, but I can't seem to figure out why I'm getting this error and any help would be appreciated: Error: cannot cast from object.Object to Rat The code I have is as

Re: Beginner problem: casting in opCmp override

2013-07-08 Thread H. S. Teoh
On Mon, Jul 08, 2013 at 02:42:30PM -0700, Jonathan M Davis wrote: On Monday, July 08, 2013 23:31:14 Ugbar Ikenaki wrote: Also…Rat is a struct, not a class. Herein might lie the problem. So, this is Rat's opCmp, correct? If it's a struct, it makes no sense for it to take an Object. Object is

Re: Beginner problem: casting in opCmp override

2013-07-08 Thread Ugbar Ikenaki
Wow! You guys are fast and helpful! Thank you Jonathan and Ali! I already got it to work, and Ali, your book is great! I've read about the first 150 pages. I'll check out those operator overloading chapters for sure. -U

Re: Beginner problem: casting in opCmp override

2013-07-08 Thread Ugbar Ikenaki
And thanks for that pointer, too, H.S.

Re: Beginner problem: casting in opCmp override

2013-07-08 Thread Ugbar Ikenaki
Here's one more question: Before I knew that opEquals existed, I tried overloading the equality expressions (== and !=) in opBinary using the code below. It worked. Why would the overloaded opBinary version get called if the equality expressions are held in opEquals? I'm just interested in

Re: Beginner problem: casting in opCmp override

2013-07-08 Thread Jonathan M Davis
On Tuesday, July 09, 2013 00:35:32 Ugbar Ikenaki wrote: Here's one more question: Before I knew that opEquals existed, I tried overloading the equality expressions (== and !=) in opBinary using the code below. It worked. Why would the overloaded opBinary version get called if the equality

Re: Beginner problem: casting in opCmp override

2013-07-08 Thread H. S. Teoh
On Tue, Jul 09, 2013 at 12:35:32AM +0200, Ugbar Ikenaki wrote: Here's one more question: Before I knew that opEquals existed, I tried overloading the equality expressions (== and !=) in opBinary using the code below. It worked. Why would the overloaded opBinary version get called if the

Re: Beginner problem: casting in opCmp override

2013-07-08 Thread Jonathan M Davis
On Monday, July 08, 2013 16:38:16 H. S. Teoh wrote: On Tue, Jul 09, 2013 at 12:35:32AM +0200, Ugbar Ikenaki wrote: Here's one more question: Before I knew that opEquals existed, I tried overloading the equality expressions (== and !=) in opBinary using the code below. It worked. Why

Re: Beginner problem: casting in opCmp override

2013-07-08 Thread Jonathan M Davis
On Monday, July 08, 2013 16:48:05 Jonathan M Davis wrote: On Monday, July 08, 2013 16:38:16 H. S. Teoh wrote: On Tue, Jul 09, 2013 at 12:35:32AM +0200, Ugbar Ikenaki wrote: Here's one more question: Before I knew that opEquals existed, I tried overloading the equality expressions

Re: Beginner problem: casting in opCmp override

2013-07-08 Thread H. S. Teoh
On Mon, Jul 08, 2013 at 04:48:05PM -0700, Jonathan M Davis wrote: On Monday, July 08, 2013 16:38:16 H. S. Teoh wrote: [...] Basically, when you write x==y, the compiler looks for opEquals and opCmp. If opEquals is found, then it's rewritten as x.opEquals(y); otherwise, if opCmp is found,

Re: Beginner problem: casting in opCmp override

2013-07-08 Thread Jonathan M Davis
On Monday, July 08, 2013 16:58:03 H. S. Teoh wrote: On Mon, Jul 08, 2013 at 04:48:05PM -0700, Jonathan M Davis wrote: On Monday, July 08, 2013 16:38:16 H. S. Teoh wrote: [...] Basically, when you write x==y, the compiler looks for opEquals and opCmp. If opEquals is found, then it's