我有几个继承类,但我不知道如何创建一个默认的构造函数,地图其实是一张地图,包括ID名和其他东西的口袋妖怪继承和异常
class Pokemon {
public:
Pokemon(){}
Pokemon(std::map<std::string, std::vector<std::string> > &facts);
protected:
std::map<std::string, std::vector<std::string> > facts_;
};
class Dragon: virtual public Pokemon {
public:
Dragon() : Pokemon() {}
Dragon(std::map<std::string, std::vector<std::string> > &facts);
};
class Monster: virtual public Pokemon {
public:
Monster() : Pokemon() {}
Monster(std::map<std::string, std::vector<std::string> > &facts);
};
class Charmander: public Monster, public Dragon {
public:
Charmander() : Pokemon(), Monster(), Dragon(){}
Charmander(std::map<std::string, std::vector<std::string> > &facts);
};
class Charmeleon: public Charmander {
public:
Charmeleon() : Charmander() {}
Charmeleon(std::map<std::string, std::vector<std::string> > &facts);
};
class Charizard: public Charmeleon {
public:
Charizard() : Charmeleon() {}
Charizard(std::map<std::string, std::vector<std::string> > &facts);
};
我只是想知道如何编写该类的默认构造函数。
我的编译器不断显示错误是:
./List07.txt:10:10: error: no matching constructor for initialization of
'Charmander'
POKENAME(Charmander)
~~~~~~~~~^~~~~~~~~~~
main.cpp:276:44: note: expanded from macro 'POKENAME'
#define POKENAME(type) try { answer = new type(facts); } catch (int) {
^
./pokemon.h:148:7: note: candidate constructor (the implicit copy constructor)
not viable: no known conversion from 'const std::map<std::string,
std::vector<std::string> >' to 'const Charmander' for 1st argument
class Charmander: public Monster, public Dragon {
^
./pokemon.h:151:5: note: candidate constructor not viable: 1st argument ('const
std::map<std::string, std::vector<std::string> >') would lose const
qualifier
Charmander(std::map<std::string, std::vector<std::string> > &facts);
^
./pokemon.h:150:5: note: candidate constructor not viable: requires 0 arguments,
but 1 was provided
Charmander() : Pokemon(), Monster(), Dragon(){}
^
什么'std :: map>'又代表了什么? –
LogicStuff
默认构造函数* what *?您已经定义了默认的构造函数... – Nim
这个问题与异常无关。 – aschepler