未找到预期的getter方法

时间:2014-07-16 11:13:56

标签: objective-c getter

我只是在学习Objective-C。我在网上犯了错误

 int resultNumerator = numerator * f.denominator + denominator * f.numerator;

你能帮助我吗?

#import "Fraction.h"

@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;
}
-(void) add : (Fraction*)f
{
    // add two fractions
    // a/b + c/d = (a*d + b*c)/(b*d)

    Fraction *result = [Fraction new];
    int resultNumerator = numerator * f.denominator + denominator * f.numerator;
}
@end

1 个答案:

答案 0 :(得分:0)

替换为:

int resultNumerator = numerator * f->denominator + denominator * f->numerator;

您定义的字段不是属性。在Objective-C中访问属性我们使用.并访问字段我们使用->她使用指向类实例的指针。