• 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
Help on subclassing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help on subclassing


  • Subject: Help on subclassing
  • From: Joachim <email@hidden>
  • Date: Wed, 30 Nov 2005 15:09:19 -0800

Esteemed experts,

I'm working with 2 classes, B and C, that are quite similar to each other. One of them is a preview of the other. They both inherit from their superclass, A, that will never be instantiated (like an abstract class). All functionality that is the same for both B and C is of course placed in A, and the methods that differ are put in the respective B and C subclasses.

From within the generic code (in the A class), I'd like to call code that's declared and will be run in the respective B and C subclasses. That is, from within A I'd like to call [self someMethod], where someMethod only exists in B and C - not in A. How do I do this?

In my attempts, the compiler warns that A may not respond to someMethod which is fine, because I know it will at runtime. And it works as expected at runtime. But if someMethod returns a value, the compiler throws an error:

NSRect myRect = [self someMethod];
-> error: invalid initializer

(or

NSRect myRect;
myRect = [self someMethod];
-> error: incompatible types in assignment)

My workaround is to declare the method in A where I just return a "dummy" value, because it's never used anyway. But it's not very nice to look at and shouldn't be necessary. Any solution to this?

Thanks you for your help,
Joachim
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Help on subclassing
      • From: Jon Adelman <email@hidden>
  • Prev by Date: Re: Question about autosaveTableColumns
  • Next by Date: Re: How to interrupt a function
  • Previous by thread: instantiateNibWithOwner:topLevelObjects: usage
  • Next by thread: Re: Help on subclassing
  • Index(es):
    • Date
    • Thread