i keep getting this error: error: expected ‘)’ before ‘,’ token this is the code i'm using:

dragon(string str = "wild dragon", int level = 5);

this is inside a the dragon class definition.

dragon::dragon(str,level) {
    name = str;
    tp = ((rand() % 6) + 1);
    type = tp;
    lvl = level;
    setatk();
    setdef();
    setexpmax();
    sethpmax();
    hp = hpmax;
    setacc();
    setout(false);/* set to conscious */
}

this is where the class is instantiated:

pets[i] = new dragon(name,level);

the variables name and level where assigned earlier in the loop.

could someone give me a hint where i'm going wrong?
this is a text based rpg i'm doing for fun.

Edited 5 Years Ago by edrag: n/a

The problem might be that ye' are breaking one of the rules on the use of default arguments. Here is a excerpt from MSDN:
http://msdn.microsoft.com/en-us/library/91563f79(v=vs.80).aspx

Default arguments are used only in function calls where trailing arguments are omitted — they must be the last argument(s). Therefore, the following code is illegal:
Copyint print( double dvalue = 0.0, int prec );

A default argument cannot be redefined in later declarations even if the redefinition is identical to the original. Therefore, the following code produces an error:
Copy// Prototype for print function.
int print( double dvalue, int prec = 2 );

...

// Definition for print function.
int print( double dvalue, int prec = 2 )
{
...
}
The problem with this code is that the function declaration in the definition redefines the default argument for prec.

Edited 5 Years Ago by Clinton Portis: n/a

I fixed the function prototype like you suggested.

dragon(string str, int level = 5);

and fixed the code where it's called in main

wild = new dragon("wild dragon");

but i'm getting the same error. what else can i do?

On line 1 of your second code listing of the first post, you still need the datatypes for str and level in the constructor definition

dragon::dragon(string str,int level) {
This article has been dead for over six months. Start a new discussion instead.