未定义引用`Class :: Class(int,int,bool,char,char,bool)'

时间:2014-12-21 12:16:32

标签: c++

大家好我想在dev-c ++中编译下面的代码,编译器会显示错误:

8       C:\Users\Rend\Desktop\Chess\test.cpp    undefined reference to `Soldier::Soldier(int, int, bool, char, char, bool)'

代码由三个文件组成:

TEST.CPP

#include <iostream>
#include <new>
#include "Pawn.h"
#include "Soldier.h"
using namespace std;
int main(int argc, const char * argv[])
{
Pawn *house=new Soldier(0,0,true,'s','b',true);
return 0;
}

Soldier.h

#include"Pawn.h"
using namespace std;
#ifndef SOLDIER_H
#define SOLDIER_H
class Soldier:public Pawn{
public:
    bool first;
    char side;
    virtual bool valid(int,int,Pawn house[][8]);
    virtual void move(int,int,Pawn house[][8]);
    Soldier(int,int,bool,char,char,bool);//not working
    ~Soldier();
};
#endif

Soldier.cpp

#include <iostream>
#include "Pawn.h"
#include "Soldier.h"
using namespace std;

Soldier::Soldier(int x,int y,bool fill,char type,char side,bool first):Pawn(x,y,fill,type)//not working
{
this->first=1;
this->side=side;
}

Soldier::~Soldier()
{
cout<<endl<<"Soldier "<<x<<' '<<y<<" has been destroyed!\n";
}

bool Soldier::valid(int x,int y,Pawn house[][8])
{
if((house[x][y].fill!=1)&&first&&(side=='r')&&((this->y-y==2)||(this->y-y==1)))
    {this->first=0;
     return 1;}
else if((house[x][y].fill!=1)&&first&&(side=='r')&&((this->y-y==-2)||(this->y-y==1))&&((this->x-        x==1)||(this->x-x==-1)))
    {this->first=0;
     return 1;}
else if((house[x][y].fill!=1)&&first&&(side=='l')&&((this->y-y==-2)||(this->y-y==-1)))
    {this->first=0;
     return 1;}
else if((house[x][y].fill!=1)&&first&&(side=='l')&&((this->y-y==-2)||(this->y-y==-1))&&((this->x-x==1)||(this->x-x==-1)))
    {this->first=0;
     return 1;}
else if((house[x][y].fill!=1)&&(side=='l')&&(this->y-y==-1))
    return 1;
else if((house[x][y].fill!=1)&&(side=='r')&&(this->y-y==1))
    return 1;
else if((house[x][y].color!=this->color)&&(side=='r')&&(this->y-y==1)&&((this->x-x==1)||(this->x-x==-1)))
    return 1;
else if((house[x][y].color!=this->color)&&(side=='l')&&(this->y-y==-1)&&((this->x-x==1)||(this->x-x==-1)))
    return 1;
else
return 0;
}

void Soldier::move(int x,int y,Pawn house[][8])
{
if(valid(x,y,house))
    this->x=x;this->y=y;
}

我该怎么做(它可以来自链接还是什么?)!?

0 个答案:

没有答案
相关问题