[英]'…' is not a type c++ compilation error
我正在為任務編寫一個小型游戲,它需要使用地圖,我已經成功地將地圖放入了2d數組中,但是現在進一步研究該任務,我發現我需要在另一個函數中訪問數組Map [] [] 。 我試圖使其正常運行,但失敗了。 我用g ++遇到的錯誤是“錯誤:'Map'不是類型'任何幫助將不勝感激。
我已經搜索過,但是要么使用搜索引擎很糟糕,要么找不到與此錯誤有關的任何信息。
const int MapSZ = 10; //In Global
int Map[MapSZ][MapSZ]; // Also Global
void GetMap(ifstream&, int); //Getting the map (Proto)
GetMap(fin, Map[MapSZ][MapSZ]); //In the main function.
void GetMap(ifstream& fin, Map[MapSZ][MapSZ]) //Inserting the map into an array
void GetMap(ifstream& fin, Map[MapSZ][MapSZ])
應該:
void GetMap(ifstream& fin, int Map[MapSZ][MapSZ])
^^^^
注意, Map
是數組的名稱 ,但是您沒有提到它的type 。
如果將Map[MapSZ][MapSZ]
定義為全局對象,則正如您的注釋所指出的(即,它在main.cpp
但在main函數外部定義),則無需將其作為參數傳遞給GetMap
。 你可以簡單地做
void GetMap(ifstream& fin); //proto
int main(int argc, const char * argv[]) {
GetMap(fin);
}
void GetMap(ifstream& fin) {
//some code that uses Map[MapSZ][MapSZ]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.