1
可能重複:
How can I declare classes that refer to each other?如何通過聲明來克服循環依賴?
下面是我在.h文件中的代碼。編譯器會抱怨在CPattern中有SP對象。我不能將SP的聲明放在CPattern上面,因爲它也聲明瞭CPattern對象。我該如何解決這個問題?感謝您的幫助!
class CPattern
{
public:
CPattern(void);
~CPattern(void);
SP & Create(void);
};
class SP
{
private:
const CPattern* pPat;
public:
SP()
{
}
~SP()
{
// pointer no longer requried
delete pPat;
}
};
關於轉發聲明,請參見[本答案](http://stackoverflow.com/a/3110269/1641234)。 –