もし私がとても簡単な質問があれば(少なくとも私もそうだと思いますが)、g ++にどのような順序でクラスを「完了」させるべきかを知ることはできません。gcc:相互参照クラスのコンパイル
base.h:
#ifndef BASE_H_
#define BASE_H_
#include "otherclass.h"
class otherclass;
class base {
public:
base(otherclass* other);
protected:
otherclass* m_other;
};
#endif /* BASE_H_ */
derived.h:
#ifndef DERIVED_H_
#define DERIVED_H_
#include "base.h"
class derived : public base {
public:
derived(otherclass* other);
};
#endif /* DERIVED_H_ */
(両方の.cppファイルを対応するだけotherclass与え割り当てるコンストラクタが含まれている*に私はこの単純な例にそれを縮小しましたメンバ変数)
otherclass.h:
#ifndef OTHERCLASS_H_
#define OTHERCLASS_H_
#include "derived.h"
class otherclass {
public:
otherclass();
protected:
derived* m_derived;
};
#endif /* OTHERCLASS_H_ */
otherclass.cpp:
#include "otherclass.h"
otherclass::otherclass() {
m_derived = new derived(this);
}
それが関連している可能性があるので、私はsconsの全体の出力を貼り付けます:ベースは、この時点ではgccに未知のタイプであるよう
g++ -o base.o -c base.cpp
g++ -o derived.o -c derived.cpp
In file included from otherclass.h:4:0,
from base.h:4,
from base.cpp:1:
derived.h:8:29: error: expected class-name before '{' token
g++ -o main.o -c main.cpp
In file included from base.h:4:0,
from derived.h:4,
from derived.cpp:1:
otherclass.h:11:3: error: 'derived' does not name a type
だから、見えます不完全な型からの派生は禁止されているので、明示的に宣言しておくと、泣くことになります。
私は本当にここで問題が表示されません(もちろんエラーメッセージを除いて)。
誰かが私を啓発できますか?