继承自多个父c ++的子类

时间:2017-12-12 10:49:49

标签: c++

我正在为一个项目制作一个Windows控制台RPG,我改变了一个类继承了1个父类,并且接受了一个对象,继承了2个父类,当我现在运行它时它会导致问题第二个基类是未定义的 标题类位于

之下
 #include "GameObject.h"
  #include "BattleObject.h"
  #include "Player.h"  
  #include "Weapon.h"
  #include <string>
  #include <vector>
using namespace std;
class Monster :
    public GameObject,
    public BattleObject
{
private :
    string m_name;
    vector<string> m_drops;

public:
    Monster(std::pair<int, int> coordinates, string name, vector<string> drops, int health, int attack, int defence);
    string getName();

};

我希望它能够接收2个基类,但由于这个

它不会运行

它崩溃并且说战斗对象基类是未定义的。

1 个答案:

答案 0 :(得分:0)

你应该明确地调用每个基类的相应构造函数,因为他们可能没有隐式构造函数:

Monster(...) : GameObject(...), BattleObject(...) { ... }