看到你这个代码我真的费解啊
haveDog.basicQualities = &DogV;,希望能得到你的分析....
对象后面还接.的操作写法跟结构体相似不敢乱揣摩什么意思.....
我想的重新在主函数里面写个新结构体做实参传输这里与你一样,这是我新的代码
- //
- // main.m
- // 结构体实例变量test
- //
- // Created by imac on 15/9/11.
- // Copyright (c) 2015年 itcast. All rights reserved.
- //
- #import <Foundation/Foundation.h>
- typedef struct {int speed;float weight;}myDog;
- #pragma mark 狗的声明
- @interface Dog : NSObject
- {
-
- int _size;
- myDog _basicQualities;
- NSString *_name;
- }
- -(void)setSize:(int)size; //设置狗大小
- -(void)DisSize; //展示狗大小
- -(void)setName:(NSString *)name;//更改狗名字
- -(void)setBasicQualities:(myDog)basicQualities; //狗的所有属性
- -(void)DisbasicQualities;//展示狗的所有属性
- //-(myDog)basicQualities;
- @end
- #pragma mark 狗的实现
- @implementation Dog
- -(void)setSize:(int)size{ //设置狗大小
- if (0==size)
- size = 5;
- _size = size;
- }
- -(void)DisSize{ //展示狗大小
- NSLog(@"这狗是%d 尺",_size);
- }
- -(void)setName:(NSString *)name{//更改狗名字
- _name = name;
- }
- -(void)setBasicQualities:(myDog)basicQualities{
- _basicQualities = basicQualities;
-
- }
- //-(myDog)basicQualities
- //{
- // return _basicQualities;
- //}
- -(void)DisbasicQualities{//展示狗的所有属性
- NSLog(@"\n%d英尺的%@开始准备跑了",_size,_name);
- NSLog(@"\n速度是%d,体重是%.2f",_basicQualities.speed,_basicQualities.weight);
- }
- @end
- int main(int argc, const char * argv[]) {
- @autoreleasepool {
- //≥myDog DogV = {20,20.6f};
- Dog *haveDog = [Dog new];
- myDog a = {50,50.0f};
- [haveDog setBasicQualities:a];
-
- NSLog(@"狗的速度为:%d,重量为:%.2f",a.speed,a.weight);
- [haveDog setSize:4];
- [haveDog DisSize];
- [haveDog setName:@"旺财"];
- //[haveDog setBasicQualities:DogV];
- //[haveDog setBasicQualities:20 andiWeight:30.0f];
- [haveDog DisbasicQualities];
- }
- return 0;
- }
复制代码 |