爲什麼這段代碼不能構建?Objective C繼承:undefined symbols
我有以下文件:
shape.h:
#import <Foundation/Foundation.h>
@interface Shape : NSObject{}
-(double)getArea;
-(void)Log;
@end
circle.h:
#import "Shape.h"
@interface Circle : Shape {}
@property (assign, nonatomic, readwrite) double radius;
@end
circle.m:
#import "Circle.h"
#include <math.h>
@implementation Circle : Shape
-(void)setRadius:(double)radius{}
-(double)getArea{
return self.radius * self.radius * M_PI;
}
-(void)Log{
NSLog(@"The circle has an area of %f.", self.getArea)
}
@end
和的main.m:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "Circle.h"
int main(int argc, char * argv[]) {
Circle *c = [Circle alloc];
c.radius = 10;
[c Log];
return 0;
}
而且我有建立自己的錯誤:
Undefined symbols for architecture x86_64:
我怎麼錯過?
你的'shape.m'文件在哪裏? – rmaddy 2015-02-10 02:55:51
我以爲我可能不會實現形狀界面。謝謝。 – koryakinp 2015-02-10 02:58:29
所有的Objective-C類都需要實現。 – rmaddy 2015-02-10 02:59:45