• OC 方法和函数


    /*

     方法

     1.对象方法都是以减号 - 

     2.对象方法的声明必须写在@interface和@end之间

       对象方法的实现必须写在@implementation和@end之间

     3.对象方法只能由对象来调用

     4.对象方法归类对象所有

     函数

     1.函数能写在文件中的任意位置(@interface和@end之间除外),函数归文件所有

     2.函数调用不依赖于对象

     3.函数内部不能直接通过成员变量名访问某个对象的成员变量

     */

    #import <Foundation/Foundation.h>

    @interface Person : NSObject

    @end

    @implementation Person

    @end

    @interface Car : NSObject

    {// 成员变量实例变量

        //int wheels = 4; 不允许在这里初始化

        //static int wheels; 不能随便将成员变量当做C语言中的变量来使用

        @public

        int wheels;

    }

    - (void)run;

    - (void)fly;

    @end

    int main()

    {

        // wheels = 10;

        /*

        Car *c = [Car new];

        c->wheels = 4;

        //run();

        

        [c run];

        */

        

        void test2();

        

        test2();

        

        return 0;

    }

    @implementation Car

    - (void) fly

    {

        

    }

    /*

    void test2()

    {

        NSLog(@"调用了test2函数-%d", wheels);

    }*/

    void test()

    {

        NSLog(@"调用了test函数");

    }

    - (void)run

    {

        test();

        NSLog(@"%d个轮子的车跑起来了", wheels);

    }

    @end

  • 相关阅读:
    还没解决的问题
    USACO 1.41 The clocks
    USACO Broken Necklace
    hdu 3265 Posters
    USACO1.52 Prime Palindromes
    hdu 3068 && pku 3974 (最长回文串)(Manacher 算法)
    USACO Calf Flac
    USACO Milking Cows
    旧版RTSP协议网页视频无插件直播EasyNVR视频平台为什么无法播放H264编码视频?
    mysql的基本查询
  • 原文地址:https://www.cnblogs.com/oc-bowen/p/5034381.html
Copyright © 2020-2023  润新知