2014-09-05 54 views
0

我只是C++的新手,請耐心等待。在我的班級MyArena裏面,我製作了另一個班級的指針fighters的矢量,Fighter。有了這個矢量,我正在收集戰鬥機指針併爲它們調用函數。但我不斷收到錯誤fighters從指針調用函數向量

#include <vector> 

using namespace std; 
class Fighter; 

class MyArena { 

    vector<Fighter*> fighters; 
    int current_size = 0; 

    bool MyArena :: addFighter(string info){ 

     for (int i = 0; i < 11; i++){ 
      if (fighters[i]->getName() == n) //error that "point to incomplete pass type is not allowed?" 
       isLegit = false; 
     } 

     fighters.push_back(new Fighter(n, t, mH, st, sp, m)); //"Fighter" is incomplete type? 
     return true; 
    } 

    bool removeFighter(string name){ 
     for (int i = 0; i < 11; i++){ 
      if (fighters[i]->getName() == name)//error that "point to incomplete pass type is not allowed?" 
       fighters[i] = NULL; 
     } 
    } 

}; 

我該如何解決這個問題?

+1

「戰鬥機」未定義。將成員函數定義移出標題並放入'.cpp'文件中。 – 2014-09-05 23:32:16

+3

'尋求調試幫助的問題(「爲什麼這個代碼不工作?」)必須包含所需的行爲,特定的問題或錯誤以及在問題本身中重現問題所需的最短代碼。沒有明確問題陳述的問題對其他讀者沒有用。請參閱:[如何創建最小,完整和可驗證示例。](http://stackoverflow.com/help/mcve) – 2014-09-05 23:33:24

回答

0

您轉發此聲明類:

class Fighter; 

但你永遠不包含的文件。將這個後您的其他包括

#include "Fighter.h" 

或相對路徑去Fighter.h如果是在不同的文件夾。

+0

是的,我忘了#include班上。 – 2014-09-06 15:28:08