c ++内联函数

use*_*514 0 c++ prototype inline-functions

我对如何在C++中进行内联函数感到困惑....

让我们说这个功能.如何转向内联函数

int maximum( int x, int y, int z )
{
   int max = x;
   if ( y > max )
      max = y;
   if ( z > max )
      max = z;
   return max;
}   
Run Code Online (Sandbox Code Playgroud)

AnT*_*AnT 8

要将其转换为内联函数,您需要做两件事:

  1. 使用关键字将其声明为内联inline.
  2. 确保在使用它的每个翻译单元中都可以看到此功能的定义.这通常意味着您必须将函数的整个定义放入头文件中.