C++内联函数

其实就是原本调用一个函数的过程,被改编为被调用函数代码嵌入于调用函数代码,来节省调用函数过程中的开销。

#include<iostream>

inline double square(double x){return x*x;}

int main()
{
    using namespace std;
    double a,b;
    double c = 13.0;
    
    a = square(5.0);
    b = square(4.5 + 7.5);
    cout <<"a="<<a<<",b="<<b<<"\n";
    cout <<"c="<<c;
    cout <<",c squared = "<<square(c++)<<"\n";
    cout << "Now c="<< c << "\n";
    return 0;
}

 

posted on 2016-05-08 11:53  J·Marcus  阅读(237)  评论(0编辑  收藏  举报

导航