#include "iostream"
using namespace std;
inline void show(const int a,const string b);
int main(){
show(3,"我是一只小小鸟。");
show(4,"我是一只小小鸟。");
show(5,"我是一只小小鸟。");
return 0;
}
inline void show(const int a,const string b){
cout<<"亲爱的"<<a<<"号:"<<b<<endl;
}
上面的带码等效于:
#include "iostream"
using namespace std;
//inline void show(const int a,const string b);
int main(){
// show(3,"我是一只小小鸟。");
{
int a=3;
string b="我是一只小小鸟。";
cout<<"亲爱的"<<a<<"号:"<<b<<endl;
}
// show(4,"我是一只小小鸟。");
{
int a=4;
string b="我是一只小小鸟。";
cout<<"亲爱的"<<a<<"号:"<<b<<endl;
}
// show(5,"我是一只小小鸟。");
{
int a=5;
string b="我是一只小小鸟。";
cout<<"亲爱的"<<a<<"号:"<<b<<endl;
}
return 0;
}
//inline void show(const int a,const string b){
// cout<<"亲爱的"<<a<<"号:"<<b<<endl;
//}
输出:
亲爱的3号:我是一只小小鸟。
亲爱的4号:我是一只小小鸟。
亲爱的5号:我是一只小小鸟。
这样的话,调用内联函数的时候,程序不需要跳转到另一个位置去执行代码,所以,牌内联函数的运行速度比常规函数要快一些,但是,要占用更多的内存。
发表回复