zoukankan      html  css  js  c++  java
  • oc-15-枚举结构体

    Cat.h

    #import <Foundation/Foundation.h>
    // 颜色的枚举
    
    typedef enum{
        
      ColorBlack,
      ColorYeallow
        
    } Color;
    @interface Cat : NSObject
    {
        @public
        float _weight;   // 体重
        Color hairColor; // 毛色
    }
    
    //
    - (void)jump;
    
    //
    - (void)eat;
    @end

    Girl.h

    #import <Foundation/Foundation.h>
    #import "Cat.h"
    
    // 生日
    typedef struct
    {
        int year;
        int month;
        int day;
    
    }Birthday;
    
    @interface Girl : NSObject
    {
        @public
        NSString *_name;  // 名字
        Birthday _birth; // 生日
        BOOL _gender;     // 性别  1是男 0是女
        Cat *_cat;        //
    }
    
    // 喂猫
    - (void)feedWithCat:(Cat *)cat;
    
    // 玩猫
    - (void)playWithCat:(Cat *)cat;
    
    
    // 展示女孩信息
    - (void)show;
    @end

    Girl.m

    #import "Girl.h"
    
    @implementation Girl
    
    // 喂猫
    - (void)feedWithCat:(Cat *)cat
    {
        NSLog(@"喂猫啦!!!!");
        [cat eat];
    }
    
    // 玩猫
    - (void)playWithCat:(Cat *)cat
    {
        NSLog(@"玩猫啦////");
        [cat jump];
    }
    // 展示女孩信息
    - (void)show
    {
        //访问结构体变量用->
        NSLog(@"女孩的名字:%@,生日:%d-%d-%d,性别:%d",_name,_birth->year,_birth->month,_birth->day,_gender);
    }
    @end
  • 相关阅读:
    NGINX-HTTPS
    README
    SSH
    Ubuntu
    Python复利
    Python全双工聊天
    Python半双工聊天
    Python网络编程
    使用Python PIL库中的Image.thumbnail函数裁剪图片
    Python模块 os.walk
  • 原文地址:https://www.cnblogs.com/yaowen/p/5309050.html
Copyright © 2011-2022 走看看