麻烦看一下 这是我刚刚修改过的 我发现我的作者属性就没存进去 你说的那几个问题 貌似没有影响结果
- #import <Foundation/Foundation.h>
- @interface Person : NSObject
- {
- char *_pName;
- int _pAge;
- }
- -(void)setPName:(char *)pname;
- -(char *)pName;
- -(void)setPAge:(int)page;
- -(int)pAge;
- @end
- @implementation Person
- -(void)setPName:(char *)pname
- {
- _pName = pname ;
- }
- -(char *)pName
- {
- return (_pName);
- }
- -(void)setPAge:(int)page
- {
- _pAge=page;
- }
- -(int)pAge
- {
- return _pAge;
- }
- @end
- @interface Book : NSObject
- {
- char *_name;
- char *_chuBanShe;
- Person *_zuoZhe;
- char *_zuoZheName;
- int _zuoZheAge;
- }
- -(void)setName:(char *)name;
- -(char *)name;
- -(void)setChuBanShe:(char *)chuBanShe;
- -(char)chuBanShe;
- -(void)setZuoZheName:(char *)zuoZheName WithAge:(int)zuoZheAge;
- @end
- @implementation Book
- -(void)setName:(char *)name
- {
- _name = name;
- }
- -(char *)name
- {
- return (_name);
- }
- -(void)setChuBanShe:(char *)chuBanShe
- {
- _chuBanShe = chuBanShe;
- }
- -(char)chuBanShe
- {
- return *(_chuBanShe);
- }
- -(void)setZuoZheName:(char *)zuoZheName WithAge:(int)zuoZheAge
- {
-
- [_zuoZhe setPName : zuoZheName];
- [_zuoZhe setPAge: zuoZheAge];
- }
- @end
- int main(int argc, const char * argv[]) {
- @autoreleasepool {
- Book *b = [Book new];
- Person *p = [Person new];
- b.name = "book";
- b.chuBanShe = "chubanshe";
- [b setZuoZheName:"sda" WithAge:11];
-
- // NSLog(@"%c %d",b->_zuoZhe.pName,b->_zuoZhe.pAge);
-
- }
- return 0;
- }
复制代码 |