调用构造函数总是出现Segmentation fault,求大神帮忙所有分都送上了
Headquarter* RedCamp = new Headquarter(0,0); Headquarter* BlueCamp = new Headquarter(N+1,1);这样两个普通的Headquarter类创建对象的语句,但是程序每次一执行到这一步就会弹出:
“Program received signal SIGSEGV, Segmentation fault.”
之前出现这种情况大多是因为访问内存失败,而我就搞不懂为什么创建个对象都会出现bug,下面给出类的实现:
程序代码:
class Headquarter{ private: int num; int life; int flag; Barrack house; public: Headquarter(int a,int c); void ReportLife(); void Manufacture(int NumOfWarrior); void LoseLife(int x); void AddLife(int); int GetLife(); int GetNum(); int GetFlag(); Barrack* GetHouse(); friend bool judge(const Headquarter* th,int need); }; Headquarter::Headquarter(int a,int c):num(a),flag(c){ life = M; }后面的函数用不到就没给出来 就是这样的类,搞不明白的到底哪里出错了,希望各位帮忙!感激不尽!