Beginner problem: casting in opCmp override

Ugbar Ikenaki iken8273 at uwi.com
Mon Jul 8 14:21:59 PDT 2013


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 other = cast(Rat) o; <--- this line throws the error
         …
         //stuff to return -1, 0, or 1 to opCmp with rational 
numbers for <, >=, etc.
         …
}

Thanks to anyone who can help!


More information about the Digitalmars-d-learn mailing list