为什么我在 '@' 之前收到“解析错误”令牌”当我尝试构建这个简单的 XCode 项目时?
完成新手问题。我正在从 Kochan 的书中学习 Objective-C。当我尝试构建以下非常简单的项目时,我不断收到
“@”标记之前解析错误
引用 Fraction.h 文件中的 @property int numerator, denominator;
语句的
。这是 Fraction.h 文件:
#import <Foundation/Foundation.h>
@interface Fraction : NSObject
{
int numerator;
int denominator;
}
@property int numerator, denominator;
-(void) print;
-(void) setTo: (int) n over: (int) d;
-(double) convertToNum;
@end
这是 Fraction.m 文件:
#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
非常感谢任何帮助我理解为什么会出现解析错误的帮助。
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) print;
-(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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 Objective-C 2.0 上发现了这一点(但有趣的是 Kochan 的书中没有):“为 Mac OS X 开发的所有使用 Objective-C 2.0 的[上述]改进的 Objective-C 应用程序与之前的所有操作系统都不兼容。 10.5(豹纹)。”所以我们找到了解释。谢谢大家。
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.
你好斯科法克斯
欢迎
看来你的问题在
@property int 分子,分母;和
NSLog(@"%i/%i", 分子, 分母);
Hello Scolfax
welcome
it seems your problem in
@property int numerator, denominator; and
NSLog(@"%i/%i", numerator, denominator);