可能重复:
何时使用内联函数和何时不使用它?
我已经看到许多源代码使用与inline指令不同的语法.
namespace Foo
{
class Bar
{
public:
// 1 - inline on the declaration + implementation
inline int sum1(int a, int b) { return a + b; }
// 2 - inline on template declaration + implementation
template <typename T>
inline T sum2(T a, T b) { return a + b; }
// 3 - Nothing special on the declaration...
int sum3(int a, int b);
};
// 3 - But the inline directive goes after …Run Code Online (Sandbox Code Playgroud)