C++ 缺少类型说明符-int假定错误

C++ 缺少类型说明符-int假定错误,c++,C++,我有错误“缺少类型说明符-假定为int”。我在谷歌上搜索这个错误,但我找不到解决方法。奇怪的是,当我删除错误所在的行以及构造函数中所有对allLeagues的调用时,就不再有错误了,然后当我写同样的行时,它就正常工作了,直到我对代码进行了更改 这是我的GameManager类,它是singleton: .cpp: .h默认构造函数: GameManager::GameManager() { allLeagues[0][0] = League("LigaBBVA", 1, 1); allLeagu

我有错误“缺少类型说明符-假定为int”。我在谷歌上搜索这个错误,但我找不到解决方法。奇怪的是,当我删除错误所在的行以及构造函数中所有对allLeagues的调用时,就不再有错误了,然后当我写同样的行时,它就正常工作了,直到我对代码进行了更改

这是我的GameManager类,它是singleton:

.cpp:

.h默认构造函数:

GameManager::GameManager()
{
allLeagues[0][0] = League("LigaBBVA", 1, 1);
allLeagues[0][1] = League("Segunda Division", 1, 1);
allLeagues[1][0] = League("PremierDivision", 1, 1);
allLeagues[1][1] = League("Championship", 1, 1);

allTeams[0].SetName("Barcelona");
allTeams[0].SetAttack(100);
allTeams[0].SetDefense(90);
allTeams[0].SetLeagueX(Spanish);
allTeams[0].SetLeagueY(LigaBBVA);

allTeams[1].SetName("Real Madrid");
allTeams[1].SetAttack(90);
allTeams[1].SetDefense(90);
allTeams[1].SetLeagueX(Spanish);
allTeams[1].SetLeagueY(LigaBBVA);

allTeams[2].SetName("Manchester United");
allTeams[2].SetAttack(70);
allTeams[2].SetDefense(80);
allTeams[2].SetLeagueX(English);
allTeams[2].SetLeagueY(PremierDivision);

allTeams[3].SetName("Chelsea");
allTeams[3].SetAttack(60);
allTeams[3].SetDefense(70);
allTeams[3].SetLeagueX(English);
allTeams[3].SetLeagueY(PremierDivision);


gameDay = 1;
gameMonth = 1;
gameYear = 2013;

for (int team = 0; team < (sizeof(allTeams) / sizeof(allTeams[0])); team++)
{
    allLeagues[allTeams[team].GetLeagueX()][allTeams[team].GetLeagueY()].SetTeam(team, allTeams[team]);
}
   }
.cpp:

#包括“League.h”
联盟
{
name=“”;
开始日=1;
开始月份=1;
}
联盟::~League()
{
}
League::League(标准::字符串名称,整数起始日,整数起始月)
{
此->名称=名称;
此->开始日期=开始日期;
此->开始月份=开始月份;

std::coutLeague.h包括GameManager.h,GameManager.h包括League.h。这就是您出错的原因


查看代码,我看不出League.h应该包含GameManager.h的原因,因此删除该include,您应该会很好。

这是否暗示编译器在该特定行上了解什么是
League
的能力有问题?您能看到
League.h
包含
G吗ameManager.h
,其中包括
League.h
?嗯……据我所见,
GameManager.h
没有理由被包括在
League.h
中。从该标题中既没有获得也没有使用任何内容。在您的问题中,您似乎将.cpp和.h文件混淆了(即标记为“.cpp”的部分)包含通常会在.h文件中的内容,反之亦然。这是您的问题中的混淆,还是实际代码中的混淆?除了错误之外,我建议不要硬编码任何与联盟或团队相关的内容。只要有一个包含该信息的文件,并在运行时对其进行解析。您永远都不想修改和重新编译源代码你是不是该添加一个新的联盟和球队,对吗?(我知道)当你发布评论时,几乎一字不差地在评论中输入这个,所以很自然地…+1=P
GameManager::GameManager()
{
allLeagues[0][0] = League("LigaBBVA", 1, 1);
allLeagues[0][1] = League("Segunda Division", 1, 1);
allLeagues[1][0] = League("PremierDivision", 1, 1);
allLeagues[1][1] = League("Championship", 1, 1);

allTeams[0].SetName("Barcelona");
allTeams[0].SetAttack(100);
allTeams[0].SetDefense(90);
allTeams[0].SetLeagueX(Spanish);
allTeams[0].SetLeagueY(LigaBBVA);

allTeams[1].SetName("Real Madrid");
allTeams[1].SetAttack(90);
allTeams[1].SetDefense(90);
allTeams[1].SetLeagueX(Spanish);
allTeams[1].SetLeagueY(LigaBBVA);

allTeams[2].SetName("Manchester United");
allTeams[2].SetAttack(70);
allTeams[2].SetDefense(80);
allTeams[2].SetLeagueX(English);
allTeams[2].SetLeagueY(PremierDivision);

allTeams[3].SetName("Chelsea");
allTeams[3].SetAttack(60);
allTeams[3].SetDefense(70);
allTeams[3].SetLeagueX(English);
allTeams[3].SetLeagueY(PremierDivision);


gameDay = 1;
gameMonth = 1;
gameYear = 2013;

for (int team = 0; team < (sizeof(allTeams) / sizeof(allTeams[0])); team++)
{
    allLeagues[allTeams[team].GetLeagueX()][allTeams[team].GetLeagueY()].SetTeam(team, allTeams[team]);
}
   }
#pragma once
#include "Team.h"
#include "GameManager.h"

class League
{
public:

//Default Constructor
League();

//Overloaded Constructor
League(std::string name, int startingDay, int startingMonth);

//Destructor
~League();

void SetTeam(int, Team);

void CreateSchedule();

  private:

Team teamsInLeague[2];

std::string name;

int startingDay, startingMonth;
  };
#include "League.h"


League::League()
{
name = "";
startingDay = 1;
startingMonth = 1;
}


League::~League()
{

}

League::League(std::string name, int startingDay, int startingMonth)
{
this->name = name;
this->startingDay = startingDay;
this->startingMonth = startingMonth;
std::cout <<"Name: " << name << endl;
}

void League::SetTeam(int index, Team teamToAssing)
{
teamsInLeague[index] = teamToAssing;
}

void League::CreateSchedule()
{

}