I am getting this error in my subclass of Monster. What is going on how can I fix it so the error doesn't show up. It says No matching function from call to Enemy::Enemy()
Monster::Monster(int,int) already defined here.
class Enemy
{
public:
Enemy() = default ; // explicitly defaulted
// see: http://en.cppreference.com/w/cpp/language/initializer_list
Enemy( int EnemyHealth, int EnemyMana ) : health(EnemyHealth), mana(EnemyMana) {}
// ...
private:
int health = 0 ;
int mana = 0 ;
};
class Monster : public Enemy
{
public:
// http://www.stroustrup.com/C++11FAQ.html#inheritingusing Enemy::Enemy ; // inheriting constructor
// ...
private:
int whatever = 0 ; // note: has in-class member initialiser
};
class Monster2 : public Enemy
{
public:
Monster2() : whatever(0) {} // augmented by the implementation
// to default-construct the base class object
Monster2( int EnemyHealth, int EnemyMana )
: Enemy(EnemyHealth,EnemyMana), // initialise base class object
whatever(0) {} // initialise member object
// ...
private:
int whatever ;
};
What do you think should be here for the inhertiance to work? Like I said the errors keeps coming about I just need to know the right structure to put the Monster class in.
You can't write the initializer list in the decleration, you have to make it in the implementation. Monster(int EnemyHealth,int EnemyMana); // decleration