1.内联函数出现阿目的为了减少函数调用的时间开销
- 使用的方法在类内定义 一个函数的时候编译器默认加了 inline
- 如果在内外部定义一个函数,想要和某个类内联,取决于编译器 (比如一个开资很的代码加入inline 那么编译器只会把它当作一个普通函数对待,并不会它变成你想要的内联函数效果)
2、
1 class temp{ 2 public: 3 int amount; 4 5 //构造函数 6 temp(int amount){ 7 this->amount = amount; 8 } 9 //类的结尾了,现在我想要在内外声明一个函数是,变为 temp类的内联函数那么结果是如下 10 //普通成员函数,在类内定义时前面可以不加inline 11 void print_amount(){ 12 cout << this-> amount; 13 } 14 } 15
3、
https://www.cnblogs.com/chenwx-jay/p/inline_cpp.html
技术支持。
1 class temp{ 2 public: 3 int amount; 4 5 //构造函数 6 temp(int amount){ 7 this->amount = amount; 8 } 9 10 //普通成员函数,在类内声明时前面可以不加inline 11 void print_amount() 12 } 13 //如果下面的函数体,过大那编译器也只会把当做一个普通函数对待 14 //在类外定义函数体,必须在前面加上inline关键字 15 inline void temp:: print_amount(){ 16 cout << amount << endl; 17 }