例如:
void show1(){
cout<<"printf the message 1"<<endl;
}
inline void show2(){
cout<<"printf the message 2"<<endl;
}
int main(){
show1();
show2();
return 0;
}
表面上看,是有main()函数调用了show1()和show2()函数。
show1()函数是执行到show1()处时,转跳到show1()的函数体处,执行show1()函数后转跳回main()函数。
show2()函数是内联函数(inline),在实际执行时函数变为:
int main(){
show1();
//show2();
cout<<"printf the message 2"<<endl;
return 0;
}
即由show2()的函数体代替了show2()函数。
inline函数牺牲空间换取时间。