Я получаю это сообщение об ошибке с кодом ниже:
class Money {
public:
Money(float amount, int moneyType);
string asString(bool shortVersion=true);
private:
float amount;
int moneyType;
};
Сначала я подумал, что параметры по умолчанию не разрешены в качестве первого параметра в C ++, но это разрешено.
Вы, вероятно, переопределяете параметр по умолчанию в реализации функции. Его следует определять только в объявлении функции.
//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){
}