阅读更多
@implementation Fraction
{
int numerator;
int denominator;
}
按照书中提供的例子将实例变量放到@implementation 中,但是在编译后一直出现错误:
In file included from testFraction.m:3:
Fraction.m:7: error: inconsistent instance variable specification
Fraction.m: In function '-[Fraction print]':
Fraction.m:15: error: 'numerator' undeclared (first use in this function)
Fraction.m:15: error: (Each undeclared identifier is reported only once
Fraction.m:15: error: for each function it appears in.)
Fraction.m:15: error: 'denominator' undeclared (first use in this function)
Fraction.m: In function '-[Fraction setNumerator:]':
Fraction.m:20: error: 'numerator' undeclared (first use in this function)
Fraction.m: In function '-[Fraction setDenominator:]':
Fraction.m:25: error: 'denominator' undeclared (first use in this function)
Fraction.m: In function '-[Fraction numerator]':
Fraction.m:30: error: 'numerator' undeclared (first use in this function)
Fraction.m: In function '-[Fraction denominator]':
Fraction.m:35: error: 'denominator' undeclared (first use in this function)
Fraction.m: In function '-[Fraction convertToNum]':
Fraction.m:40: error: 'denominator' undeclared (first use in this function)
Fraction.m:41: error: 'numerator' undeclared (first use in this function)
后来将实例变量放到@interface中,在GUN中编译通过。不知道是不是编译器不同,记录之。