Re: int and short int on intel
Re: int and short int on intel
- Subject: Re: int and short int on intel
- From: Jonathan Fewtrell <email@hidden>
- Date: Fri, 12 Jan 2007 17:49:27 +0800
On 12 Jan 2007, at 12:21, Sherm Pendley wrote:
On Jan 11, 2007, at 10:00 PM, Jonathan Fewtrell wrote:
On 12 Jan 2007, at 10:22, Chris Suter wrote:
On 12/01/2007, at 1:12 PM, Jonathan Fewtrell wrote:
I have two classes, JF1 and JF2, each of which has an ivar
called 'scale' of type int, with normal getter and setter
accessors.
As part of an array-sorting routine, I use -
sortedArrayUsingFunction:, the function in question being as
follows:
int JFSortByScale( id panel1 , id panel2, void *context )
*snip* - It's the declaration that's important here. :-)
To solve it, you should cast panel1 and panel2 to the expected type.
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.
You could create a protocol that declares the -scale method:
@protocol ScalablePanel
-(int) scale;
@end
Then, make sure that both JF1 and JF2 are declared as implementing
your protocol:
@interface JF1 : NSObject <ScalablePanel>
...
@end
And finally, in the declaration of your sort function, you'd
declare the objects as ids - i.e. any class - but declare the
protocol as well:
int JFSortByScale( id<ScalablePanel> panel1, id<ScalablePanel>
panel2, void *context)
{
...
}
As an added bonus, this will also get rid of the compiler warning. :-)
Excellent. Thanks, everyone, for the various suggested solutions.
_______________________________________________
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