2014-12-28 20 views
0

我不確定我的編譯器在這裏需要什麼。它給了我下面的錯誤Undeclared Identifier(newGame) - 指針作爲參數

error C2065: 'newGame' : undeclared identifier 

相關代碼:

void createMenu() { 
    MenuItem newGameOption = MenuItem("../art/newGame.bmp", newGame); 
} 
//start a new game 
void newGame() { 

} 

在MenuItem.h

class MenuItem { 
    bool selected = false; 
    std::string path; //Path to menu item's art 

    void *pf(); //Function to execute upon selection 

public : 
    MenuItem(const char*, void pf()); //constructor 
}; 
+2

在'createMenu()'上面聲明'newGame()'。 – 0x499602D2

回答

1

編譯器錯誤似乎是非常簡單的。無論「新遊戲」是什麼,編譯器都對此一無所知。這是它第一次看到這個名字。

事實上,你有一個稍後在文件中定義的newGame()函數,顯然沒有幫助。當編譯器試圖編譯第一個函數時,它沒有讀取它。

這裏有一些谷歌食物給你:「前瞻性聲明」。把:

void newGame(); 

在createMenu()之前,以便編譯器知道它是什麼。

+0

由於某種原因,這給了我大量的新錯誤。將它們添加到原始問題 – Matt

+0

修正它忽略...謝謝! – Matt