私には2つのクラスがPet
あり、Person
Person.h は次のとおりです。
#ifndef PERSON_H
#define PERSON_H
#include <list>
class Pet;
class Person
{
public:
Person();
Person(const char* name);
Person(const Person& orig);
virtual ~Person();
bool adopt(Pet& newPet);
void feedPets();
private:
char* name_;
std::list<Pet> pets_;
};
#endif
そして、これがPet.hです
#ifndef PET_H
#define PET_H
#include <list>
#include "Animal.h"
class Person;
class Pet : public Animal
{
public:
Pet();
Pet(const Pet& orig);
virtual ~Pet();
std::list<Pet> multiply(Pet& pet);
private:
std::string name_;
Person* owner_;
};
#endif
私が抱えている問題はこれです:
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/list.tcc:129: error: invalid use of undefined type `struct Pet'
Person.h:13: error: forward declaration of `struct Pet'
これを配置しようとして修正しましたstd::list<Pet>* pets_;
が、リスト関数を呼び出そうとすると、常にリンクの問題が発生します。私の質問は、別のクラスのオブジェクトを含むクラス内にリストを含める必要がある方法です。