2013-11-24 38 views
-1

我有錯誤「缺少類型說明符 - int假定」。我GOOGLE了這個錯誤,但它無法找到解決方案。奇怪的是,當我刪除錯誤所在的行和構造函數中allLeagues的所有調用時,所以再也沒有錯誤,然後再次寫入相同的行時,它正常工作,直到我對代碼進行更改。缺少類型說明符 - int假定錯誤

這裏是我的遊戲管理器類,這是單:

的.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() 
{ 

} 

在此先感謝。

+2

這是不是遠程向你建議,那個* specific *行上的編譯器能夠知道'League'是什麼?你能看到'League.h'包含'GameManager.h',其中包含'League.h'?嗯......從我所看到的,'GameManager.h'沒有理由包含在'League.h'中。沒有任何東西從頭部獲得或使用。 – WhozCraig

+0

在你的問題中,你似乎混有.cpp和.h文件(即,標有「.cpp」的部分包含通常在.h文件中的內容,反之亦然。你的問題,還是它在實際的代碼中混合? – oefe

+0

拋開錯誤,我建議不要硬編碼任何聯盟或團隊相關的任何東西,只要有一個包含該信息的文件,並在運行時解析它,你想在每次添加一個新的聯盟和團隊時修改和重新編譯源代碼,對嗎?(我知道) –

回答

2

League.h包含GameManager.h,GameManger.h包含League.h。這是你錯誤的原因。

看着代碼我看不到League.h應該包含GameManager.h的理由,所以刪除包含,你應該沒問題。

+0

當你發佈它時,在評論中直接輸入這個近乎完整的評論,所以很自然... +1 = P – WhozCraig

+0

非常感謝@john,現在錯誤消失了! – Stefan

相關問題