I have several inheritance class, but I do not know how to create a default constructor for that, the map fact is a map that includes ID name and other thing for a pokemon
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);
};
I just want to know how to write the default constructor for the class.
My complier keeps showing errors that:
./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(){}
^
The compiler tries to tell you what's wrong here:
no known conversion from 'const std::map<std::string, std::vector<std::string> >'
So, apparently facts
is const, but all your (extremely odd) constructors take a reference to non-const, so they cannot be used.