"Does not recognize selector", but it's there.
I'm a CS major, so I know this means that ObjC can't find the "-print" method in List, but I can't seem to convince it that it's there. It also doesn't seem to be running the appropriate "new" and "init" commands (I don't get the output from printf() in either one of those methods)
Even more infuriating is that, when compiling on a RedHat machine, it runs just fine. I'm not sure what I'm missing.
Below is my code and the command I use to compile:
------
List.h:
#import <objc/Object.h>
@interface List : Object
{
int list\[100\];
int size;
}
- (int) addEntry: (int) x;
- print;
- free;
- resetSize;
- init;
+ new;
@end
------
List.m:
#import "List.h"
#import <stdio.h>
@implementation List
+ new
{
printf("in new\n");
self = \[super new\];
return self;
}
- init
{
size = 0;
printf("in init\n");
fflush(stdout);
return self;
}
- free
{
return \[super free\];
}
- (int) addEntry: (int) x
{
list[size] = x;
size++;
return size;
}
{
int i;
for (i = 0; i < size; i++)
{
printf("%d->", list\[\i\]); //ignore the slash in front of the 'i'. It's there so the forum formatting doesn't italicize things.
}
printf("\.\n");
return self;
}
- resetSize
{
size = 0;
return self;
}
@end
------
main.m
#import <objc/Object.h>
#import "List.h"
int main()
{
id foo;
foo = \[List new\];
\[foo print\];
\[foo free\];
return 1;
}
-------------------
</code>
The command: gcc -Wall -lobjc main.m List.m
I'm compiling on an iMac Core 2 Duo running 10.4.10.
Any ideas why it might not be finding the selector?
iMac Core Duo 2GHz, Mac OS X (10.4.10)