由于我使用“分子”的方式存在问题,我收到此错误和其他许多错误。和分母'变量:"不一致的实例变量规范"
我是Objective C的新手,所以我不确定如何解决这个简单的问题。
#import <Foundation/Foundation.h>
@interface Fraction: NSObject
-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;
@end
@implementation Fraction
{
int numerator;
int denominator;
}
-(void) print
{
NSLog (@"%i/%i", numerator, denominator);
}
-(void) setNumerator: (int) n
{
numerator = n;
}
-(void) setDenominator: (int) d
{
denominator = d;
}
@end
int main (int argc, char * argv[])
{
@autoreleasepool {
Fraction *myFraction;
myFraction = [Fraction alloc];
myFraction = [myFraction init];
[myFraction setNumerator: 1];
[myFraction setDenominator: 3];
NSLog (@"The value of myFraction is:");
[myFraction print];
}
return 0;
}