具有國家或大陸的Map.h下面的代碼不被認定這個問題提交不明身份標識C++,但它的標識
Map.h:
#ifndef MAP_H
#define MAP_H
#include<string>
#include<vector>
#include<iostream>
#include<fstream>
//#include "Country.h"
using namespace std;
class Map{
private:
vector<Country> countries;
vector<Continent> continents;
vector<vector<int> > adjacents;
string author;
string image;
string wrap;
string scroll;
string warn;
public:
Map(ifstream);
Map();
void save();
void setAdjacent(Country&, Country&);
void placeWithin(Continent&, Country&);
int numOfCountries();
int numOfContinents();
bool verify();
bool isAdjacent(Country*, Country&);
bool hasAdjacent(Country*);
bool hasCountry(Continent&);
};
#endif
無論添加的評論包括,我仍然得到錯誤。
下面是其他兩個文件
Continent.h:
#ifndef CONTINENT_H
#define CONTINENT_H
#include "Map.h"
using namespace std;
class Continent
{
private:
string name;
int bonus;
vector<Country> countries;
public:
void addCountry(Country&);
int getOwner();
int getBonus();
int getSize();
string getName();
bool hasCountry(Country&);
};
#endif
Country.h:
#ifndef COUNTRY_H
#define COUNTRY_H
#include "Continent.h"
using namespace std;
class Country{
private:
static int nextCountryNumber;
int countryNumber;
Map map;
string name;
int x, y;
Continent continent;
vector<Country> adjacents;
public:
Country(string, int, int, Continent&, Map&);
string getName();
int getX();
int getY();
Continent getContinent();
bool isAdjacentTo(Country&);
bool hasAdjacent();
void addAdjacent(Country&);
string toString();
};
#endif
我認爲它的某種循環引用的,但我不能找到此是這樣的...
爲什麼要在Continent.h中包含Map.h? –
@XiaotianPei,因爲'Country'中使用'Map','Country.h'包含'Continent.h',其中包含'Map.h' – GreatAndPowerfulOz
通常在頭文件中使用forward聲明而不是'include'。否則,您可能會遇到循環依賴關係。另外,具體是什麼錯誤?你能把它粘貼在這裏嗎? – personjerry