• 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
New Obj-C root class and forwarding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

New Obj-C root class and forwarding


  • Subject: New Obj-C root class and forwarding
  • From: Christopher Sean Morrison <email@hidden>
  • Date: Tue, 18 Mar 2003 02:27:40 -0500

I'm writing some test classes for fairly academic reasons and I've run
into some questions. I'm playing with the class heirarchies and
restrictions of the inheritance mechanisms. The problems I've run into
stem around trying to create a new root class that inherits from a root
interface.

My goal was to create a new root class (i.e. that does not inherit from
NSObject (or Object for that matter)) that conforms loosely to some
interface that defines minimal abstract functionality and data. The
problem I get is that I get a run-time error regarding message forwarding:

objc: Shape: Does not recognize selector forward::
Abort trap

I believe I roughly understand the parent forwarding mechanism and the
error given would imply that that is one of potentially a handful of class
mechanisms that I'd need to implement to generate a new root class. Is
this true? At a minimum, this would imply that there are objective-C
run-time semantics that are being assumed by linking with the -lobj
library.

So, here's some code. Please remember that this is all just academic.
that said, we start with a root interface:

@interface Shape {
int x;
int y;
}
- (int)x;
- (int)y;
- (int)x: (int)aNumber;
- (int)y: (int)aNumber;
@end

And then we create a new root class that conforms to the Shape interface:

#import "Shape.h"
@interface Circle:Shape {
int radius;
}
+ (Circle *)x: (int)xValue y: (int)yValue radius: (int)aRadius;
- (int)radius;
- (int)radius: (int)aNumber;
@end

The Circle instantiator is presently as follows:

@implementation Circle
+ (Circle *)x: (int)xValue y: (int)yValue radius: (int)aRadius {
return self ;
}
.
.
.
@end

Finally, the driver test code:

#import "Circle.h"
main() {
int i;
Circle *shape[100];
for (i=0; i<100; i++) {
shape[i] = [Circle x: rand() y: rand() radius: rand()];
}
}

At a naive attempt to quell the error, I add a "forward" class method to
Circle that simply returns self. This quells the error about Circle not
responding to forward, and results in the error shown about about Shape
not responding to forward. If I add the same class method to Shape, the
error persists. If I subclass Shape off of NSObject, all is quelled.

1) Can anyone explain what is going on?

2) Can anyone explain how to get what I'm attempting to do to work without
subclassing off of a root class/interface?

Cheers!

Sean Morrison
U.S. Army Research Laboratory
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Help Book Problems
  • Next by Date: How to capture left & right mouse down?
  • Previous by thread: Re: Convert Image in NSImage to TIFF/PICT Format
  • Next by thread: RE: New Obj-C root class and forwarding
  • Index(es):
    • Date
    • Thread