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

时间:2013-11-24 11:07:20

标签: c++

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

这是我的GameManager类,它是singleton:

的.cpp:

#ifndef GameManager_H
#define GameManager_H

#include "PlayedMatch.h"
#include "League.h"


class GameManager
{
 public:

void Update(); // Called every frame

void AdvanceOneDay();

static GameManager &GetInstance();

Team allTeams[4]; //This var holds all the teams

League allLeagues[2][2]; //Error in this line. Also another error mising ; before identifier allLeagues



enum Leagues
{
    Spanish,
    English
};

enum SpanishLeagues
{
    LigaBBVA,
    SegundaDivision
};

enum EnglishLeagues
{
    PremierDivision,
    Championship
};

 private:

int gameDay, gameMonth, gameYear;

void operator=(GameManager const&);

//Default Constructor
GameManager();

//Destructor
~GameManager();

 };

#endif

.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]);
}
   }

联赛类: .H:

#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;
  };

的.cpp:

#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()
{

}

提前致谢。

1 个答案:

答案 0 :(得分:2)

League.h包含GameManager.h,GameManger.h包含League.h。这就是你错误的原因。

查看代码,我认为League.h没有理由应该包含GameManager.h,所以删除包含,你应该没问题。

相关问题