Re: int and short int on intel
Re: int and short int on intel
- Subject: Re: int and short int on intel
- From: John Stiles <email@hidden>
- Date: Thu, 11 Jan 2007 19:07:38 -0800
On Jan 11, 2007, at 7:00 PM, Jonathan Fewtrell wrote:
Thanks Chris. This confirms my understanding of ObjC was wrong. I
thought that if an object was typed id, the method called would
only be determined at runtime and the return type would be the type
of that method. From what you are saying, it seems that the return
type will be set at compile time (short int in this case) and will
not be changed to the return type of the method that is actually
called at runtime. That's a pity because it means my naming scheme
is constrained by names used in classes that I am not even using
(NSDecimalNumber in this case).
As regards casting, I don't see how I can cast in this case because
I do not know which class panel1 and panel2 will be. They can each
be JF1 or JF2. That's why I used id in the function declaration.
A clean solution: make a base class which JF1 and JF2 both subclass
from. This class can declare that "scale" is a function returning
int. The function body is irrelevant since all subclasses will
override it (you could throw an exception, assert, or return zero,
your choice).
Then in the sorting function, cast the object to this base class.
Or, as a hack, you could just cast the object to JF1. Even if it's
actually an object of type JF2, things will "just work" at runtime
because the actual function call truly is dynamic—it's just the
return values that need to be determined at compile time.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden