出于某种原因,我无法弄清楚在不同文件中我在c ++中的继承有什么问题。我得到的最大错误是“没有匹配函数来调用'Enemy :: Enemy(int&)'
这是我的Monster.cpp代码
#ifndef MONSTER_H
#define MONSTER_H
#include "Enemy.h"
class Monster : public Enemy
{
Monster();
Monster(int MonsterHealth, int MonsterMana,int Monstersize);
void TheenemyHealth()
{
int Enemyhealth = 100;
}
int EnemyDamage(int EnemyAttack){
int Attack = EnemyAttack;
Attack = 5;
}
int dropxp(int enemyxpdrop);
private:
int Health = 0;
int Mana = 0;
};
#endif // MONSTER_H
这是我的Monster.h
#include "Enemy.h"
Enemy::Enemy(int EnemyHealth,int EnemyMana)
{
Attackpower;
Strenght;
Enemyxp;
}
Enemy::~Enemy()
{
//dtor
}
这是我的enemy.cpp
#ifndef ENEMY_H
#define ENEMY_H
class Enemy
{
public:
Enemy(int EnemyHealth,int EnemyMana);
~Enemy();
virtual void TheenemyHealth(){}
virtual int EnemyDamage(int EnemyAttack){
int Attack = EnemyAttack;
}
virtual int dropxp(int enemyxpdrop);
private:
int Attackpower= 0;
int Strenght = 0;
int Enemyxp= 0;
};
#endif // ENEMY_H
和我的敌人。
{{1}}
答案 0 :(得分:2)
您的敌人构造函数定义为Enemy(int EnemyHealth,int EnemyMana);
,但您只使用一个参数调用它:
Monster::Monster(int MonsterHealth,int MonsterMana,int Monstersize) // implementation
: Health(MonsterHealth), Mana(MonsterMana), Enemy(Monstersize)
{}
你的Enemy
构造函数也没有做任何事情:
Enemy::Enemy(int EnemyHealth,int EnemyMana)
{
Attackpower; // does nothing
Strenght; // does nothing
Enemyxp; // does nothing
}