C++:内联函数(inline)

 

首先,欢迎并感激博友进行知识补充与修正。


#include <iostream>

using namespace std;

//1 inline关键字和函数体的实现写在一块
inline void fun()
{
	int a = 0;
	cout << "a:" << a << endl;
}


int main()
{
	fun();
	//2 C++编译器直接将函数体插入在函数调用的地方
	//3 内联函数省去了普通函数调用时压栈,跳转和返回的开销
	/*{
		int a = 0;
		cout << "a:" << a << endl;
	}*/
	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/feissss/article/details/88076717