i have this files:
//Q2a.h
#ifndef Q2A_H
#define Q2A_H
inline int MyFactorial(int a)
{
if (a < 2)
return 1;
return a*MyFactorial(a-1);
}
int NumPermutations(int b);
#endif
//Q2a.cpp
#include "Q2a.h"
int NumPermutations(int b)
{
return MyFactorial(b);
}
and file with the main- Q2b.cpp
i notice that the compiler usually ignore the inline decleration when there are recursive functions . but my question is why if i remove the inline declaration, i can do:
g++ -Wall -g -c Q2a.cpp -o Q2a.o
g++ -Wall -g -c Q2b.cpp -o Q2b.o
those are fine, but in the linkage stage:
g++ -Wall -g -c Q2a.o Q2b.o -o Q2
i get an error: multiple definition of `MyFactorial(int)