c++ - 样式 : Inline on the function declaration

标签 c++ coding-style inline

<分区>

Possible Duplicate:
When should I write the keyword 'inline' for a function/method?

我不是 100% 确定,但据我所知,如果我在 hpp 文件上声明一个带有函数体的函数,它将被视为标记为内联(编译器将决定要做什么),我意思是:

//myfile.hpp
class StackOverflow{
public:
    void overflow(){_overflow = true;}
...
}

将等同于:

//myfile.hpp
class StackOverflow{
public:
    ***inline*** void overflow(){_overflow = true;}
...
}

如果我错了,那么问题就结束了,但除此之外,我真的很喜欢将函数标记为内联函数,即使这不是必需的,通用代码样式指南是否对此有任何说明?

非常感谢

最佳答案

由于在此上下文中提及关键字 inline 没有提供任何信息,因此将其保留。这只是视觉上的困惑。

如果有一个选项可以使内联定义的函数成为非内联的,这将是另一回事(考虑 private-by-default 作为这样的例子):在这里,它可能是认为即使这是默认设置,明确选择也会使其更容易理解。但这里别无选择。无论您做什么,在类体内定义的成员函数都是内联

事实上,将其显式标记为 inline 类似于提供其他推断信息。你不会写下面的吧?

#define member
#define function

class StackOverflow{
public:
    member function inline void overflow() { _overflow = true; }
}

关于c++ - 样式 : Inline on the function declaration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12705343/

相关文章:

html - 无法让导航列表内联显示

c++ - 使用 const var& 在 C++ 中传递引用

c++ - 在 buildbot 上构建后,Qt 应用程序变为 Windows 旧样式

c++ - 在哪里 Hook 编码约定脚本?

border - 仅在环绕文本的底部添加边框

javascript - 三元表达式 JavaScript 中的三元表达式

c++ - 无法使用嵌套的 lambda 捕获静态成员

c++ - C++类中的运算符重载函数

c - 为什么参数类型声明在括号外?

Ruby 1.9.3-p140 - 使用线程 - 如何等待所有结果从线程中出来?