Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
通常我更喜欢完全拆分声明和定义,因此,我倾向于在其中定义内联方法,.cpp 我只是希望链接优化器在它用于不同的编译单元时内联它。
.cpp
我的问题是:
如果你标记你的函数inline,那么你必须在每个使用它的翻译单元中提供一个定义。这与将定义放在单个.cpp.
inline
如果你想把一个函数放在一个单一的.cpp你不应该声明它inline。如果你想内联函数,你必须依赖你的工具链,将合适的优化标志传递给你的编译器和链接器。您的工具链实际上将内联哪些功能是您必须试验的东西。
根据您的工具链,您可以使用特定于实现的属性来装饰您的函数,以指示您想要内联哪些函数。