I have class called Champion contain a vector of pairs (string and double). I have a problem while comparing element of vector with another string.
#pragma once
#include <string>
#include<vector>
using namespace std;
class Champion : public Game
{
protected:
vector<std::pair<string, double> > melee_champ = { { "yasuo",0 }, { "garen",0 }, { "jax",0 }, { "fiora",0 }, { "fizz",0 } };
vector<std::pair<string, double> > ranged_champ = { {"varus",0 }, {"ezreal",0}, {"lux",0}, {"zoe",0}, {"vayne",0} };
public:
Champion();
void write_champ_to_file(string f_name);
void delete_champ(string type, string name);
};
This is my class and in the implementation I have :
void Champion::delete_champ(string type, string name)
{
if (type == "melee champ")
{
for (pair<string, double>& x : melee_champ)
{
if (x.first == name)
{
auto itr = std::find(melee_champ.begin(), melee_champ.end(), name);
melee_champ.erase(itr);
Champion::write_champ_to_file("temp.txt");
remove("champ.txt");
rename("temp.txt", "champ.txt");
}
}
}
}
The problem is in comparing (x.first == name).
How can I overload == operator ?
This is the error that I get:
Error C2676 binary '==': 'std::pair' does not define this operator or a conversion to a type acceptable to the predefined operator