2014-09-05 68 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