Answers for "error: default argument given for parameter"

C++
1

error: default argument given for parameter

/*
You are probably redefining the default parameter in the implementation of the function. 
It should only be defined in the function declaration.
*/
//bad (this won't compile)
string Money::asString(bool shortVersion=true){
}

//good (The default parameter is commented out, but you can remove it totally)
string Money::asString(bool shortVersion /*=true*/){
}

//also fine, but maybe less clear as the commented out default parameter is removed
string Money::asString(bool shortVersion){
}
Posted by: Guest on September-24-2021

Code answers related to "error: default argument given for parameter"

Browse Popular Code Answers by Language