Why do I get a "parse error before '@' token" when I try to build this simple XCode project?
Complete newbie question. I'm learning Objective-C from Kochan's book. When I try to build the following very simple project, I keep getting a
parse error before '@' token
referring to the @property int numerator, denominator;
statement in the Fraction.h file.
Here is the Fraction.h file:
#import <Foundation/Foundation.h>
@interface Fraction : NSObject
{
int numerator;
int denominator;
}
@property int numerator, denominator;
-(void) pr开发者_开发问答int;
-(void) setTo: (int) n over: (int) d;
-(double) convertToNum;
@end
Here is the Fraction.m file:
#import "Fraction.h"
@implementation Fraction
@synthesize numerator, denominator;
-(void) print
{
NSLog(@"%i/%i", numerator, denominator);
}
-(void) setTo: (int) n over: (int) d
{
numerator = n;
denominator = d;
}
-(double) convertToNum
{
if (denominator != 0)
return (double) numerator/denominator;
else
return 1.0;
}
@end
Any help in understand why I am getting that parse error is much appreciated.
I found this on Objective-C 2.0 (but interestingly not in Kochan's book): "All Objective-C applications developed for Mac OS X that make use of the [above] improvements for Objective-C 2.0 are incompatible with all operating systems prior to 10.5 (Leopard)." So we've found the explanation. Thank you all.
Hello Scolfax welcome it seems your problem in @property int numerator, denominator; and NSLog(@"%i/%i", numerator, denominator);
精彩评论