Some points about 'inline'.
- inlining is not a universally "bad idea", it certainly won't decrease performance. It might significantly increase object size.
- It isn't the case that the "inline" keyword is used to tell the compiler to inline code (bizarrely).
- It's use is mandatory when it is needed, and a noop when it is not.
- It is used to allow you to put member function definitions outside the class declaration in header files that are included from multiple locations. If you do not include it, then the second module that includes it will generate a linker error as it finds multiple definitions for the same function.
class SomeClass {
void someInline( int y ) { x = y; }
int x;
};
is exactly the same as
class SomeClass {
void someInline( int );
int x;
};
inline void SomeClass::someInline( int y )
{
x = y;
}
- inline on a virtual member is ignored. It's impossible to have an inline virtual.
- inline in the module and not the header will either give linker errors (when other modules don't find the exported symbol, or be ignored.
- Finally: inlining can be dangerous during multiple compile cycles if the function changes if dependent modules are not recompiled, since the old version of the function could have been inlined into another module, and you end up with module A having inlined version1 and module B inlined version2.
- Declaring a function 'static' in a C program when that function is not declared in the header means that the symbol is not exported, and allows the compiler to inline as it see fit. 'inline' is utterly unnecessary to make the function be inlined.
HTH.