ファイルを相互にリンクする際に問題があります。私が使用しているクラスがあります:
ファイル Ah のクラス A のヘッダー
class A
{
public:
B someVariable; //there is class B used!!
int number;
};
ファイル Bh のクラス B のヘッダー
class B
{
public:
void someMethod();
};
Bの実装
B::someMethod()
{
cout << "Value is:" << globalInstanceOfA.number << "\n";
}
そして、別のファイルで、プログラム全体で使用するグローバル変数 globalInstanceOfA を宣言する必要があります...
しかし、include や extern などをどこに置くかがわかりません。私はそのようなことを試しました:
#include "A.h"
#include "B.h"
extern A globalInstanceOfA;
誰かが私を助けることができますか?