我正在学习 Objective-c 编程,有两个错误我无法解决。你能告诉我有什么问题吗?
#import "Fraction.h"
int main (int argc, char * argv[]) {
@autoreleasepool {
Fraction *aFraction = [[Fraction alloc] init];
Fraction *bFraction = [[Fraction alloc] init];
[aFraction setTo: 1 over: 4];
[bFraction setTo: 1 over: 2];
[aFraction print];
NSLog (@"+");
[bFraction print];
NSLog (@"=");
[aFraction add: bFraction]; /*error 1: No visible @interface for 'Fraction' declares the selector 'add:'*/
[aFraction reduce];
[aFraction print]; }
return 0; }
#import <Foundation/Foundation.h>
@interface Fraction : NSObject
@property int numerator, denominator;
-(void) print;
-(void) setTo: (int) n over: (int) d;
-(double) convertToNum;
-(void) add: (Fraction *) f;
-(void) reduce; /*error 2: Expected identifier or '(' */
@end