What's the difference between using the inline keyword before a function and just declaring the whole function in the header?
so...
int whatever() { return 4; }
vs
.h:
inline int whatever();
.cpp:
inline int myClass::whatever()
{
return 4;
}
for that matter, what does this do:
inline int whatever() { return 4; }
There are several facets:
Language
inline
keyword, then its definition should be available in the TU or the program is ill-formed.inline
.inline
(implicitly or explicitly) may be defined in several TUs (respecting the ODR), whereas it is not the case for regular functions.inline
ones.Compiler behavior
inline
will be emitted as a weak symbol in each object file where it is necessary, this may increase their size (look up template bloat).Linker behavior