Hey guys, I'm a complete noob with regards to Design Patterns and classes in c++, just looking for some advice.
I keep getting these errors:
MedicFactory.o: In function `MedicFactory::createSurvivor(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
MedicFactory.cpp:(.text+0x68): undefined reference to `Medic::setName(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
MedicFactory.cpp:(.text+0xf6): undefined reference to `Medic::setPrimary(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
MedicFactory.cpp:(.text+0x177): undefined reference to `Medic::setSecondary(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
MedicFactory.cpp:(.text+0x1b7): undefined reference to `Medic::setHP(int)'
MedicFactory.cpp:(.text+0x1ca): undefined reference to `Medic::setDamage(int)'
collect2: ld returned 1 exit status
make: *** [task2] Error 1
here is my code:
SurvivorFactory.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
class SurvivorFactory
{
public:
SurvivorFactory() {}
virtual ~SurvivorFactory() {}
virtual Survivor* createSurvivor(string) = 0;
};
|
MedicFactory.h:
1 2 3 4 5 6 7 8
|
class MedicFactory : public SurvivorFactory
{
public:
MedicFactory() {}
~MedicFactory() {}
Survivor* createSurvivor(string);
};
|
MedicFactory.cpp:
1 2 3 4 5 6 7 8 9 10 11 12
|
Survivor* MedicFactory::createSurvivor(string name)
{
Medic *medic = new Medic(name);
medic->setName(name);
medic->setPrimary("Syringe");
medic->setSecondary("Surgical Scalpel");
medic->setHP(8);
medic->setDamage(2);
return medic;
}
|
Medic.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
class Medic : public Survivor
{
public:
// constructs a survivor with the specified name
Medic(string);
~Medic();
/*virtual*/ bool hitZombie(Zombie*);
/*virtual*/ void celebrate();
/*virtual*/ bool getHit(Zombie*) ;
/*virtual*/ void die() ;
void setName(string);
void setPrimary(string);
void setSecondary(string);
void setHP(int);
void setDamage(int);
};
|
medic.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
class Medic : public Survivor
{
public:
// constructs a survivor with the specified name
Medic(string);
~Medic();
/*virtual*/ bool hitZombie(Zombie*);
/*virtual*/ void celebrate();
/*virtual*/ bool getHit(Zombie*) ;
/*virtual*/ void die() ;
void setName(string);
void setPrimary(string);
void setSecondary(string);
void setHP(int);
void setDamage(int);
};
|
Survivor.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
class Survivor
{
protected:
string name;
int hp;
string primaryWeapon;
string secondaryWeapon;
int damage;
public:
Survivor(string);
~Survivor();
void attack(Zombie*);
virtual bool hitZombie(Zombie*) = 0;
virtual void celebrate() = 0;
virtual bool getHit(Zombie*) = 0;
virtual void die() = 0;
void setName(string);
void setPrimary(string);
void setSecondary(string);
void setHP(int);
void setDamage(int);
};
|
Survivor.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
Survivor::Survivor(string name)
: name(name), hp(1), primaryWeapon("Right Hand"), secondaryWeapon("Left Hand"), damage(1)
{
cout << "Recruiting a Survivor!" << endl; //Do not change this line
}
Survivor::~Survivor()
{
}
//Do not change this function.
void Survivor::attack(Zombie *z)
{
cout << name << " attacks a Zombie!" << endl;
while (hp > 0)
{
if (hitZombie(z))
{
// The zombie died, celebrate and move on with life.
celebrate();
return;
}
else
{
if (getHit(z))
{
// Got killed by the zombie. Survivor now dies.
die();
}
}
}
};
|
I know this error has something to do with not implementing the constructor, however I am unable to chase it down.
Any help would be appreciated.
Thanks.