Click here to Skip to main content
15,888,170 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When compile I get the error redefinition of default parameter : parameter 4

What I have tried:

I have compiled , but did not work
Posted
Updated 19-Jan-18 23:45pm
v2
Comments
Patrice T 19-Jan-18 17:53pm    
And you have some source code?
jeron1 19-Jan-18 17:57pm    
You're going to have to show some relevant code.

You must carefully read the codeline where the error is happening. I guess that you have an default parameter not only in the header declaration but also in the code implementation.

A default parameter is only used in the declaration. If it doesnt solve the problem provide all related code and the full error message text.
 
Share this answer
 
[updated, thanks to Richard]
C++ default arguments[^] must be specified either in function (or method) declarations or in function (or method) definitions.
Specifying it in both declaration and definition is an error.
The preferred approach is specifying it only in function (or method) declarations.


For example
C++
// function declarations
int my_add( int a, int b =  5);
int my_sub( int a, int b = -1);
// ..
// function definitions
int my_add( int a, int b = 5) //<- WRONG, default parameter repeated in function definition
{
  return (a + b);
}
int my_sub( int a, int b) //<- fine
{
  return (a -b);
}

[/update]
 
Share this answer
 
v2
Comments
Richard MacCutchan 20-Jan-18 6:40am    
Not strictly true. If you don't use declarations then the defaults must be specified in the definition.
CPallini 20-Jan-18 7:36am    
You are right, thank you for pointing it out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900