I have a declaration of an inline function that happens to be recursive. Since it’s recursive there is no point in declaring it inline so why does my linkage fail when i remove it?
3 files:
\\File1.h
#ifndef FILE1_H
#define FILE1_H
inline int Factorial(int a)
{
if (a < 2)
return 1;
return a*Factorial(a-1);
}
int PermutationsNum(int b);
#endif
\\File1.cpp
#include "File1.h"
int PermutationsNum(int b)
{
return Factorial(b);
}
\\File2.cpp
#include <iostream>
#include "File1.h"
int main()
{
std::cout << "permutations of 7 elements: " << PermutationsNum(7) << std::endl;
return 0;
}
inlinetells the compiler not to export the symbol. If you don’t use it, the symbol will be exported by all compilation units that include that file, thus resulting in a multiple definition.3.2 One definition rule [basic.def.odr]
This is the only pertinent use of the keyword
inlinein fact – actually inlining functions is up to the compiler.IMO, the keyword is even less than a hint in that sense.