学习object-c时遇到的一个问题,报了一大堆的错,半天没头绪.原来是小问题,记载一下

来源:互联网 发布:哔哩哔哩录制软件 编辑:程序博客网 时间:2024/04/28 02:14
@import <Foundation/Foundation.h>@interface people : NSObject{    @public    int age;    char sex;}- (void) walk;@end@implementation people- (void) walk{    NSLog(@"%c走了一段路,年纪%d",sex,age);}@endvoid 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';    ~~  ^


贴出部分错误,

分析了好长时间.
只是在头部引入的标签出错了

结果是解决了,


是应该用# 而不是用@



只是在头部引入的标签出错了
0 0
原创粉丝点击