我遇到了一個循環包含引用錯誤,我希望在CardFactory中使用Deck類型的對象,並在Deck中使用CardFactory類型的對象。有關如何解決這個問題的任何提示?在C++頭文件中解析循環引用
//CardFactory.h
#ifndef CARDFACTORY_H
#define CARDFACTORY_H
#include "Deck.h"
#include <string>
using std::string;
class CardFactory {
public:
Deck getDeck();
static CardFactory* getFactory() {
static CardFactory singleton;
return &singleton;
}
};
#endif
//Deck.h
#ifndef DECK_H
#define DECK_H
#include <vector>
#include <iostream>
#include "CardFactory.h"
using std::ostream;
class Deck : public std::vector<Card*> {
friend ostream& operator<<(ostream& os, const Deck& dt);
Card* draw();
Deck(CardFactory* cf);
};
#endif
類不應從載體和其他STL容器繼承。 – 2016-12-02 03:59:51