Functions that are defined inside class scope are implicitly
inline
and ODR (One Definition Rule) is implicitly also accomplished.
Usually to satisfy ODR you put the inline keyword on your functions, however compiler is free not to inline your function regardless of where this function is defined.
As you can see the inline keyword has double meaning, conclusion is:
If you define your functions outside class scope they are not inline by default,
If you define a function inside class scope it is implicitly inline for ODR.
Any function to be a candiate for inline function must be defined in header file (.h file)
ODR is always guaranteed, however inlining is not regardless of inline keyword.
Keep in mind that function which is defined inside class can be marked as
inline
(the keyword is not redundant there like some believe it is),
also keep in mind that template function is also subject to inlining and inline keyword, regardless if defined in or outside class scope.
For example, template function defined in header outside class can be marked as inline,
and that keyword is also not redundant there.
The only difference between template and naked function is that you can't put template definition into source file.
If you do, then your template class or function looses some of it's generic behavior by design.
In particular you'll have to explicitly instatiate stuff ahead of time.
What is ODR (One Definition Rule)?
Basically a rule such that function is not defined multiple times, ex. ODR is broken if function is defined in header without inline keyword, see also:
https://en.wikipedia.org/wiki/One_Definition_Rule
EDIT:
OK-so I guess it is only a convenience/syntax thing with no processor operational issues. |
There is performance impact in that your function can be selected for inline expansion.
This also brings memory use overhead, however small\big it may be.