passing a struct to a constructor

struct charType
{
int health;
int strength;
int constitution;
int stamina;
int per;
short colorCode;
char character;
bool friendly;
};

charType goblin = {50, 2, 3, 40, 2, 10, 'g', false};
charType wolf = {18, 3, 2, 50, 3, 7, 'w', false};

oCharacterObjectMap["goblin"] = Character(46, 3, 1, "goblin", goblin);
oCharacterObjectMap["wolf"] = Character(2, 1, 1, "wolf", wolf);;

class Character
{
private:

public:
int x, y;
int health;
int healthMax;
int strength;
int constitution;
int stamina;
int staminaMax;
int per;
int nCurrentMap;
short colorCode;
std::string charName;
char character;
bool friendly;
int hasSpoken;
int hasSeen[MAP_WIDTH][MAP_HEIGHT*MAPS];
std::pair<int,int> LastSeen;
int cartography;


int staminaAdjust( int );
int healthAdjust( int );
Character();
void setLastSeen();
Character(int, int, int, int, int, int, int, int, short, char *, char, bool);
Character::Character(int, int, int, char*, charType);
friend class boost::serialization::access;
template<typename Archive>
void serialize(Archive& ar,const unsigned version)
{
ar & x & y & health & health & healthMax & strength & constitution & stamina
& staminaMax & per & nCurrentMap & colorCode & charName & character &
friendly & hasSpoken;
}
~Character(void);
};

Character::Character(int xPos, int yPos, int map, char * name, charType type)
{
x = xPos;
y = yPos;
health = type.health;
strength = type.strength;
constitution = type.constitution;
stamina = type.stamina;
per = type.per;
nCurrentMap = map;
colorCode = type.colorCode;
charName = name;
character = type.character;
friendly = type.friendly;
healthMax = constitution * 10;
staminaMax = constitution * 10 + 10;
hasSpoken = 0;
std::memset(hasSeen,0,sizeof(hasSeen));
LastSeen.first=0;
LastSeen.second=0;
cartography =0;
}

but when i compile i get this

error C2665: 'Character::Character' : none of the 4 overloads could convert all the argument types
1> could be 'Character::Character(int,int,int,char *,charType)'
1> while trying to match the argument list '(int, int, int, const char [5], int
Last edited on
Can you post the class declaration?
added class declaration as asked
Your fourth argument expects a point to modifiable chars but you are passing it a constant char. Your function should probably be taking a const char* as an argument.
changed to const char *, but the compiler thinks the struct is an int for some reason when it gets passed to the class constructor
You can try passing by reference:

Character::Character(int, int, int, char*, charType&);
Topic archived. No new replies allowed.