Beginner problem: casting in opCmp override
Jonathan M Davis
jmdavisProg at gmx.com
Mon Jul 8 14:28:44 PDT 2013
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 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!
You're going to need to provide more code than that. Without knowing anything
about Rat, we can't help you.
On a side note, I point out that talking about compiler errors as being
"thrown" is going to cause confusion, as throwing is something completely
different.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list