When I run this code:
void Damage(int damage, string source) {
if (source == "melee") {
damage = (damage / Strength) - Armour;
Health -= damage >= 0 ? damage : 0;
};
Log.push_back(("Damage " + to_string(damage)) + (" from " + source));
if (Health <= 0) {
Death();
}
};
I get this error about the operator in bold:
Severity Code Description Project File Line Suppression State Details
Error C2677 binary '==': no global operator found which takes type 'const _Ty' (or there is no acceptable conversion)
with
[
_Ty=std::string
] Hello World C:Program FilesMicrosoft Visual Studio2022CommunityVCToolsMSVC14.39.33519includexmemory 2225
I am using C++ in Visual Studio 2022
I though that this would result in the string in the parameter being checked, but it says that the data type isn’t the same.
New contributor
Isaac Kennedy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
7