What are 'inline' functions, and does the compiler always respect the inline keyword?
Last updated
As an optimization,
inlineis only a hint to replace calls with the function body. The compiler may ignore it (large or recursive functions) or inline unmarked functions.The guaranteed meaning is a linkage rule: it relaxes the one-definition rule so identical definitions can appear in multiple translation units, which is why inline functions live in headers.
Member functions defined inside a class body are implicitly
inline. Over-inlining bloats code, so trust the optimizer and link-time optimization.