开发者

Simple command line object-c project, it can't find my Person.h class?

I created a simple Person.h class:

#import <Foundation/Foundation.h>


@interface Person : NSObject 
{
    int age;
    int height;

}

-(void) print;
-(void)setAge: (int) a;
-(void)setHeight: (int) h;

@end

And its implement开发者_高级运维ation in Person.m:

#import "Person.h"


@implementation Person

-(void) print
{
    NSLog(@"You are %i years old, and %i feet tall", age, height);
}

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

@end

Both files are in the /source folder.

Now in the main file test2.m:

#import <Foundation/Foundation.h>
#import <Person.h>
int main (int argc, const char * argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];



    Person *p1 = [[Person alloc] init];
    Person *p2 = [[Person alloc] init];

    [p1 setAge:30];
    [p1 setHeight:6];

    [p2 setAge:25];
    [p2 setHeight:5];

    [p1 print];
    [p2 print]

    [pool drain];

    return 0;   
}

I'm getting a 'no such file or directory' error at the import statement for Person.h.

And as a result the lines referring to Person are also resulting in errors.

Why can't the file be found?

This is a xcode, command line project, using the foundation lib.


Change this:

#import <Person.h>

To this:

#import "Person.h"

Oh and you're missing a semicolon here:

[p2 print]


@Blankman

if you use #import <Person.h> means that the compiler is going to look for the class where its classes are stored. if you use #import "Person.h", the compiler will look in your project folder for the class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜