Correctly matching function constructor calls

I've been working on a database program using classes. Its the most complex C++ program I've made so far and I keep finding one particular error turning up in my class header. This is the code with only the constructors for the classes and relavant formulas.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//Class header

#include<cstring>
#include<string>
#ifndef CARD_CLASS_H_INCLUDED
#define CARD_CLASS_H_INCLUDED
using namespace std;
class Card //Abstract base class
{
protected:
string sName;
string sCard_num;
char cLimit;
short int nOwn;

//Access Functions. Protected as they are not used by non-member functions
string Getname(){return sName;}
string Getnumber(){return sCard_num;}    
char Getlimit(){return cLimit;}          
short int Getstock(){return nOwn;}       

public:
//Constructors & destructor
Card(){sName="Unknown"; sCard_num="00000000"; cLimit='-'; nOwn=0;}
Card(const string &title,const string &cnum, char restr, short int stock)
{sName=title; sCard_num=cnum; cLimit=restr; nOwn=stock;}
~Card(){}
};

class Monster: public Card
{
protected:
short int nAttribute;
short int nLevel;
short int nMonsterType;
short int nTuner;
short int nAttack;
short int nDefence;

//Access Functions
short int GetAttr(){return nAttribute;}
short int GetLvl(){return nLevel;}
short int GetType(){return nMonsterType;}
short int GetTuner(){return nTuner;}
short int GetAtk(){return nAttack;}
short int GetDef(){return nDefence;}

public:
//Constructors & Destructors
Monster(){nAttribute=0;nLevel=0;nMonsterType=0;nTuner=0;nAttack=0;nDefence=0;}

Monster(short int attr, short int lvl, short int mtype, short int tuner,
short int atk, short int def, string &title, string &cnum, char restr, 
short int stock):Card(title, cnum, restr, stock)
{nAttribute=attr;nLevel=lvl;nMonsterType=mtype;nTuner=tuner;nAttack=atk;nDefence=def;}
~Monster(){}
};

class Effect_Monster: public Monster
{
private:
string sMonster_Effect;

public:
Effect_Monster(){sMonster_Effect="None";}

Effect_Monster(string &meffect, short int attr, short int lvl, short int mtype,
short int tuner, short int atk, short int def,string &title, string &cnum, 
char restr, short int stock): Monster(attr, lvl, mtype, tuner, atk, def, title,
cnum, restr, stock)
{sMonster_Effect=meffect;}

/*Constructor using an already created monster class.
This is where the error turns up.*/
Effect_Monster(char *meffect, const Monster &v): Monster(GetAttr(), GetLvl(),
GetType(), GetTuner(), GetAtk(), GetDef(),
/*This is divided here because the division is here in the original code and 
the error is on the following line accorrding to the debugger*/
Getname(), Getnumber(), Getlimit(), Getstock())
{sMonster_Effect=meffect;}
};


My debugger goes through this and throws an error on line 79 as follows:
79 error:no matching function for call to 'Monster::Monster(short int, short int, short int, short int, short int, short int, std::string, std::string, char short int)'
note: candidates are: Monster::Monster(short int, short int, short int, short int, short int, short int, std::string&, std::string&, char short int)
note: Monster::Monster()
note: Monster::Monster(const Monster&)

What changes do I need to make to this code to get rid of this error?
Thanks in advance
Last edited on
When passing temporary objects as a reference, the reference must be const.
Add the const qualifiers for the strings in the Monster constructor and it will be fine.
It might also be advisable to have Getname and Getnumber have return a constant reference to the internal string objects. That way no string copies are being created when calling these functions and the interface itself does not change by that modification.
Last edited on
Of course. Thank you so much.
Thank you for not pointing out how big an idiot I am: I did it for Card but not Monster <facepalm>.

It compiles fine now. Thanks again
Topic archived. No new replies allowed.