Linker error if there is no Inline function defined in the header file?

Not a built-in function defined in the protected header file

#if !defined(HEADER_RANDOM_H)
#define HEADER_RANDOM_H 
void foo()
{
//something
}
#endif

Results in linker error: already defined in someother.obj file Executing the inline function works fine, but I cannot understand why the function already throws an error in the first case.

+5
source share
3 answers

If the header is included in more than one source file and the function is not marked as "inline", you will have several definitions. Included guards only prevent multiple inclusions in the same source file.

+9
source

. , inline -, . , inline , ( ).

+7

, , .

+4

All Articles