• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: int and short int on intel
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: int and short int on intel
      • From: Chris Suter <email@hidden>
References: 
 >int and short int on intel (From: Jonathan Fewtrell <email@hidden>)
 >Re: int and short int on intel (From: Chris Suter <email@hidden>)
 >Re: int and short int on intel (From: Jonathan Fewtrell <email@hidden>)

  • Prev by Date: Re: int and short int on intel
  • Next by Date: Problem drawing offscreen with NSOpenGLView (gets drawn onscreen too)
  • Previous by thread: Re: int and short int on intel
  • Next by thread: Re: int and short int on intel
  • Index(es):
    • Date
    • Thread