内联C ++代码 [英] Inlining C++ code

查看:105
本文介绍了内联C ++代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码有什么区别:

class Foo  
{
  inline int SomeFunc() { return 42; }
  int AnotherFunc() { return 42; }
};

这两个函数都会被内联吗?内联实际上有什么区别吗?有什么规则,什么时候你应该或不应该内联代码?我经常使用 AnotherFunc 语法(例如访问器),但我很少直接指定 inline

Will both functions gets inlined? Does inline actually make any difference? Are there any rules on when you should or shouldn't inline code? I often use the AnotherFunc syntax (accessors for example) but I rarely specify inline directly.

推荐答案

两个表单都应该以完全相同的方式内联。对于在类定义中定义的函数体,Inline是隐式的。

Both forms should be inlined in the exact same way. Inline is implicit for function bodies defined in a class definition.

这篇关于内联C ++代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆