I'm getting an error when I call to Describe() function on the bottom, in the main:
sword.Describe();
I could just override the functions for each weapon class but I would like to use the defined function in the abstract class.
The idea is to use the Describe() function of the abstract class for everything, is this possible?
This is the code:
#include <iostream>
enum WeaponType
{
SWORD,
AXE,
BOW,
SPEAR
};
class Weapon
{
public:
int damage;
std::string name;
WeaponType weaponType;
virtual int GetDamage() = 0;
virtual int Swing() = 0;
void Describe()
{
std::cout << "This weapon is a " << this->weaponType << " named as " << this->name
<< " with damage of " << this->damage << std::endl;
}
};
class Sword : Weapon
{
public:
Sword(std::string name)
{
this->damage = 3;
this->name = name;
this->weaponType = WeaponType::SWORD;
}
int GetDamage() override
{
return this->damage;
}
int Swing() override
{
return this->damage;
}
};
int main()
{
Sword sword("Excalibur");
sword.Describe();
}