declaration mistake

what is the mistake in this declaration? I am not able to figure out please help.

int fun1(float var1,int k,int i=0,int j)
Once you have a default argument, all remaining parameters must have default values as well.
A default argument may not occur in the middle of the parameter list unless all parameters to the right of that argument also have default arguments.

int fun1(float var1, int k, int i=0, int j=0) ; is legal.
int fun1(float var1 = 0.0f, int k, int i, int j) ; is not.

One can get around this by overloading the function:

 int fun1(float var1, int k, int i, int j )
    // ...

int fun1(float var1, int k, int j)
    return fun1(var1, k, 0, j) ;

although that obviously gets a little hairy if you want to provide overloads with different variables of the same type elided from the parameter list. You might google the Named Parameter idiom if you find it necessary.

Last edited on
Can you please post the error the compiler gave you?
Topic archived. No new replies allowed.