zoukankan      html  css  js  c++  java
  • OC 对象和函数

    #import <Foundation/Foundation.h>

    @interface Car : NSObject

    {// 成员变量

        @public

        int wheels;

        int speed;

    }

    - (void)run;

    @end

    @implementation Car

    - (void)run

    {

        NSLog(@"%d个轮子,速度为%dkm/h的车子跑起来", wheels, speed);

    }

    @end

    void test(int w, int s)

    {

        w = 20;

        s = 200;

    }

    void test1(Car *newC)

    {

        newC->wheels = 5;

    }

    void test2(Car *newC)

    {

        Car *c2 = [Car new];

        c2->wheels = 5;

        c2->speed = 300;

        

        newC = c2;

        newC->wheels = 6;

    }

    int main()

    {

        Car *c = [Car new];

        c->wheels = 4;

        c->speed = 250;

        

        //test(c->wheels, c->speed);

        //test1(c);

        test2(c);

        

        [c run];

        

        return 0;

    }

  • 相关阅读:
    Android笔记
    Scala中apply的用法
    MySQL备忘
    Spring test
    Scala
    Dubbo
    Scala元组
    Scala中None, Nil, Nothing的区别
    java多态与异常处理——动手动脑
    《大道至简》第七八章读后感
  • 原文地址:https://www.cnblogs.com/oc-bowen/p/5034378.html
Copyright © 2011-2022 走看看