'no match for 'operator+' (operand types are 'std::basic_string<char>' and 'double') c++
double vitesse();
string description();
string toString()
{
return nom + " : " + description() + "\nvitesse : " + vitesse() + ", poids : " + poids;
}
this code is part of class I'm testing, and whene i try to compile it the error in the title pops up return nom + " : " + description() + "\nvitesse : " + vitesse() + ", poids : " + poids; in this line and i can't understand why?
Solution 1:[1]
It's because the function vitesse() returns a double value, which can't be concatenated as-is with strings. I believe if you replace vitesse() in the return value with to_string(vitesse()), it would work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Remy Lebeau |
