ここに2つのクラスがあります。それTreeをとと呼びましょうFruit。ATreeは、常に1つだけまたはまったく持つことができませんFruit。AFruitは1つだけにできますTree。オブジェクトから、関数でTree取得できます。オブジェクトから、オブジェクトを返す関数によってその「所有者」を取得できます。FruitgetTreeFruit( )FruitgetFruitOwner( )Tree
これでTreeヘッダーに次のようになります。
#include "Fruit.h"
class Tree {
private:
Fruit m_Fruit; // The fruit in the tree.
public:
Tree ( Fruit tree_fruit );
Fruit getTreeFruit( ); // Returns m_Fruit.
}
そしてFruitヘッダーに:
#include "Tree.h"
class Fruit {
private:
Tree m_Owner; // The Tree object that "owns" the fruit.
public:
Fruit ( Tree fruit_owner );
Tree getFruitOwner( ); // Returns m_Owner.
}
お互いのヘッダーファイルをインクルードすると、エラーが発生するTreeことに気づきました。Fruitエラーを修正するにはどうすればよいですか?
よろしくお願いします。:)