Objective-C:使用未声明的标识符 [英] Objective-C: Use of undeclared identifier

查看:82
本文介绍了Objective-C:使用未声明的标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可能犯了一个愚蠢的错误,但是我正在研究《 Objective-C中的编程》一书,虽然遇到了一些错误,但是我似乎找不到错误。

I know I'm probably making a stupid mistake but I'm working my way through the book Programming in Objective-C and I'm getting a couple of errors but I cant seem to find the mistake.

person.m

#import "person.h"

@implementation person{
    int age;
}
-(void) print{
    NSLog(@"the person is %i years old", age);

}
-(void) setAge:(int)a{
    age = a;
}

@end

person.h

#import <Foundation/Foundation.h>

@interface person : NSObject
-(void) print;
-(void) setAge: (int)a;
@end

main

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        person *newPerson; //error is on this line use of undeclared identifier:person


    }
    return 0;
}


推荐答案

您需要导入人员。您要使用Person类的所有文件中的h标头,因此添加

You need to import person.h header in all files you want to use Person class, so add

#import "person.h"

主文件行

这篇关于Objective-C:使用未声明的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆