码迷,mamicode.com
首页 > 其他好文 > 详细

内联函数

时间:2015-01-27 01:45:49      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:

内联函数

为什么要把函数的声明和函数的定义分开,直接合并的成员函数不是更加简便方便吗?

内联函数的好处就是在函数定义处的代码,复制到调用函数处,这样就省去了函数的跳转,增加了效率,内联函数适用于代码少的函数中,不然会导致代码体积过大,反而对程序的运行效率不好,所以我们在使用内联函数的时候,需要注意。

#include<iostream.h>
class Humn{


private :
    int height;
public :
    inline void set_height(int h);
    int show();

};

void Humn::set_height(int h){

    if(h>0 && h<100)
    {
        height = h;
    }else{
    
        cout<<"输入的数值不正确";
    }

}

int Humn::show(){


    return height;

}




int main()
{
    Humn mike;
    mike.set_height(60);
    cout<<mike.show();
    cout<<"\n";
    Humn jack;
    jack.set_height(50);
    cout<<jack.show();


    return 0;
}

 

内联函数

标签:

原文地址:http://www.cnblogs.com/aicpcode/p/4251717.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!