ここに2つのクラスがあります。それTree
をとと呼びましょうFruit
。ATree
は、常に1つだけまたはまったく持つことができませんFruit
。AFruit
は1つだけにできますTree
。オブジェクトから、関数でTree
取得できます。オブジェクトから、オブジェクトを返す関数によってその「所有者」を取得できます。Fruit
getTreeFruit( )
Fruit
getFruitOwner( )
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
エラーを修正するにはどうすればよいですか?
よろしくお願いします。:)