@import <Foundation/Foundation.h>
@interface people : NSObject
{
@public
int age;
char sex;
}
- (void) walk;
@end
@implementation people
- (void) walk
{
NSLog(@"%c走了一段路,年纪%d",sex,age);
}
@end
void main()
{
people *p1 = [people new];
p1->age=20;
p1->sex='F';
people *p2 = [people new];
p2->age=30;
p2->sex='M';
[p1 walk];
[p2 walk];
return;
}
在学习中的一段最简单的代码
报错如下
people.m:1:1: error: use of '@import' when modules are disabled
@import <Foundation/Foundation.h>
^
people.m:14:1: error: '@end' must appear in an Objective-C context
@end
^
people.m:17:17: warning: cannot find interface declaration for 'people'
@implementation people
^
people.m:21:5: warning: implicitly declaring library function 'NSLog' with type
'void (id, ...)'
NSLog(@"%c走了一段路,年纪%d",sex,age);
^
people.m:21:5: note: please include the header <Foundation/NSObjCRuntime.h> or
explicitly provide a declaration for 'NSLog'
people.m:21:41: error: use of undeclared identifier 'sex'
NSLog(@"%c走了一段路,年纪%d",sex,age);
^
people.m:17:17: warning: class 'people' defined without specifying a base class
[-Wobjc-root-class]
@implementation people
^
people.m:17:23: note: add a super class to fix this problem
@implementation people
^
people.m:29:26: warning: class method '+new' not found (return type defaults to
'id') [-Wobjc-method-access]
people *p1 = [people new];
^~~
people.m:30:9: error: 'people' does not have a member named 'age'
p1->age=20;
~~ ^
people.m:31:9: error: 'people' does not have a member named 'sex'
p1->sex='F';
~~ ^
分析了好长时间.
只是在头部引入的标签出错了
结果是解决了,
是应该用# 而不是用@
只是在头部引入的标签出错了