I get this error...
error C2664: '__thiscall Warrior::Warrior(char *,int,int,char *,int)' : cannot convert parameter 1 from 'const class Character' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
... on the code below and cannot trace any threads that indicate how to resolve this in the class contructor, if that's where it should be fixed. Any ideas? The relevant code is included below. I can provide the rest of it if needed.
//define base class
class Character
{
protected:
char * name;
int hit_pts;
int armor_class;
public:
Character(char* n="Anonymous", int h = 0, int a = 0);
Character(const Character&);
~Character(void);
virtual bool isalive(void);
virtual operator const char*(void) const;
virtual operator int(void);
//operator
Character& operator =(const Character&);
};
//define base class constructor
Character::Character(char* n, int intHitPts, int intArmorClass):hit_pts(intHitPts), armor_class(intArmorClass)
{
name = new char[strlen
+1];
strcpy(name, n);
}
//define base class copy constructor
Character::Character(const Character& Ch):hit_pts(Ch.hit_pts), armor_class(Ch.armor_class)
{
name = new char[strlen(Ch.name)+1];
strcpy(name,Ch.name);
}
//define base class destructor
Character::~Character(void)
{
delete []name;
}
//define member function. returns hit_pts value as true/false
bool Character::isalive(void)
{
return hit_pts>0?true:false;
}
//create cast operator to return object name
Character:
perator const char *(void) const
{
return name;
//return static_cast <Character> name;
}
//create cast operator to return armor_class
Character:
perator int(void)
{
return armor_class;
}
//create copy operator for class
Character& Character:
perator =( const Character& c)
{
if (&c!=this)
{
delete []name;
name = new char[strlen(c.name)+1];
strcpy(name, c.name);
hit_pts = c.hit_pts;
armor_class = c.armor_class;
}
return *this;
}
//create/define warrior class
class Warrior: virtual public Character
{
protected:
char * weapon;
int damage_pts;
public:
Warrior(char* n="Anonymous Warrior",int h=0, int a= 0, char* w="n/a", int d=0);
Warrior(const Warrior&);
//Warrior(const Character&);
Warrior& operator=(const Warrior&);
~Warrior(void);
int strikes(void);
};
//create warrior class constructor
Warrior::Warrior(char* n, int d, int a, char* w, int h)
:Character(n,h,a),weapon(w), damage_pts(d)
{
weapon = new char[strlen(w)+1];
strcpy(weapon,w);
}
error C2664: '__thiscall Warrior::Warrior(char *,int,int,char *,int)' : cannot convert parameter 1 from 'const class Character' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
... on the code below and cannot trace any threads that indicate how to resolve this in the class contructor, if that's where it should be fixed. Any ideas? The relevant code is included below. I can provide the rest of it if needed.
//define base class
class Character
{
protected:
char * name;
int hit_pts;
int armor_class;
public:
Character(char* n="Anonymous", int h = 0, int a = 0);
Character(const Character&);
~Character(void);
virtual bool isalive(void);
virtual operator const char*(void) const;
virtual operator int(void);
//operator
Character& operator =(const Character&);
};
//define base class constructor
Character::Character(char* n, int intHitPts, int intArmorClass):hit_pts(intHitPts), armor_class(intArmorClass)
{
name = new char[strlen
strcpy(name, n);
}
//define base class copy constructor
Character::Character(const Character& Ch):hit_pts(Ch.hit_pts), armor_class(Ch.armor_class)
{
name = new char[strlen(Ch.name)+1];
strcpy(name,Ch.name);
}
//define base class destructor
Character::~Character(void)
{
delete []name;
}
//define member function. returns hit_pts value as true/false
bool Character::isalive(void)
{
return hit_pts>0?true:false;
}
//create cast operator to return object name
Character:
{
return name;
//return static_cast <Character> name;
}
//create cast operator to return armor_class
Character:
{
return armor_class;
}
//create copy operator for class
Character& Character:
{
if (&c!=this)
{
delete []name;
name = new char[strlen(c.name)+1];
strcpy(name, c.name);
hit_pts = c.hit_pts;
armor_class = c.armor_class;
}
return *this;
}
//create/define warrior class
class Warrior: virtual public Character
{
protected:
char * weapon;
int damage_pts;
public:
Warrior(char* n="Anonymous Warrior",int h=0, int a= 0, char* w="n/a", int d=0);
Warrior(const Warrior&);
//Warrior(const Character&);
Warrior& operator=(const Warrior&);
~Warrior(void);
int strikes(void);
};
//create warrior class constructor
Warrior::Warrior(char* n, int d, int a, char* w, int h)
:Character(n,h,a),weapon(w), damage_pts(d)
{
weapon = new char[strlen(w)+1];
strcpy(weapon,w);
}