#import <Foundation/Foundation.h>
#pragma 生日结构体声明
struct birthday {
int year;
int month;
int day;
};
#pragma 学生类声明
@interface Student : NSObject
{
@public
NSString *_name;
struct birthday _birthday;
}
-(void)printInfo;
@end
#pragma 学生类实现
@implementation Student
-(void)printInfo{
//printf(@"姓名:%@,生日%d,%d,%d;\n",_name,_birthday.year,_birthday.month,_birthday.day);
NSLog(@"姓名:%@,生日%d,%d,%d;\n",_name,_birthday.year,_birthday.month,_birthday.day);
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
//NSLog(@"Hello, World!");
Student * darin = [Student new];
darin -> _name = @"darin";
darin -> _birthday = (struct birthday){1990,1,1};
[darin printInfo];
}
return 0;
}
|
|