您的位置:首页 > 其它

58,结构体作为对象属性

2015-12-05 18:21 260 查看
#import <Foundation/Foundation.h>

typedef struct{

int kDateyear;

int kDatemonth;

int kDateday;

} Date;

@interface Person :
NSObject

{

@public

NSString *_name;

Date _birthday;

}

-(void)printf;

@end

@implementation Person

-(void)printf{

NSLog(@"_name = %@,date = %i,%i,%i",_name,_birthday.kDateyear,_birthday.kDatemonth,_birthday.kDateday);

}

@end

int main(int argc,
const char * argv[]) {

@autoreleasepool {

Person *p = [Person
new];

p->_name =
@"ljs";

p->_birthday = (Date){1991,4,21};

[p printf];

}

return 0;

}

//2015-12-05 18:18:59.054 2,结构体作为对象属性[963:168487] _name = ljs,date = 1991,4,21

//Program ended with exit code: 0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: