evan
2010-05-03, 01:04
here are some very simple classes I'm trying to get working just so I can move on from there to more complicated things:
listtest.m
#import <stdio.h>
#import "lst.h"
int main (void) {
Lst *l = [Lst new];
[l x: 10];
printf("%i\n", [l x]);
return 0;
}
lst.h
#import <objc/Object.h>
@interface Lst : Object
{
@private
int x;
}
- (id) x: (int) x_value;
- (int) x;
@end
lst.m
#import "lst.h"
@implementation Lst
- (id) x: (int) x_value {
x = x_value;
return self;
}
- (int) x {
return x;
}
@end
and here's what happens:
Evan-Daviss-iMac:code Evan$ gcc *.m -lobjc
listtest.m: In function ‘main’:
listtest.m:10: warning: ‘Lst’ may not respond to ‘+new’
listtest.m:10: warning: (Messages without a matching method signature
listtest.m:10: warning: will be assumed to return ‘id’ and accept
listtest.m:10: warning: ‘...’ as arguments.)
this code very closely resembles the tutorial I'm following which also does not have an init method, so i'm being led to believe it's not entirely necessary... and even when I try to add one it doesn't work, and gives the same warning with alloc and init that it does with new in this example. ugh, why is this so difficult!!
listtest.m
#import <stdio.h>
#import "lst.h"
int main (void) {
Lst *l = [Lst new];
[l x: 10];
printf("%i\n", [l x]);
return 0;
}
lst.h
#import <objc/Object.h>
@interface Lst : Object
{
@private
int x;
}
- (id) x: (int) x_value;
- (int) x;
@end
lst.m
#import "lst.h"
@implementation Lst
- (id) x: (int) x_value {
x = x_value;
return self;
}
- (int) x {
return x;
}
@end
and here's what happens:
Evan-Daviss-iMac:code Evan$ gcc *.m -lobjc
listtest.m: In function ‘main’:
listtest.m:10: warning: ‘Lst’ may not respond to ‘+new’
listtest.m:10: warning: (Messages without a matching method signature
listtest.m:10: warning: will be assumed to return ‘id’ and accept
listtest.m:10: warning: ‘...’ as arguments.)
this code very closely resembles the tutorial I'm following which also does not have an init method, so i'm being led to believe it's not entirely necessary... and even when I try to add one it doesn't work, and gives the same warning with alloc and init that it does with new in this example. ugh, why is this so difficult!!