私はこのファイルを持っています:
//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
再帰関数がある場合、コンパイラは通常、インライン宣言を無視することに気付きました。しかし、私の質問は、インライン宣言を削除すると、次のことができる理由です。
g++ -Wall -g -c Q2a.cpp -o Q2a.o
g++ -Wall -g -c Q2b.cpp -o Q2b.o
それらは問題ありませんが、リンケージ段階では:
g++ -Wall -g -c Q2a.o Q2b.o -o Q2
エラーが表示されます: `MyFactorial(int) の複数の定義