lundi 11 janvier 2021

Removing Struct object from list using remove method in C++

I am trying to use remove method from list on struct object to remove it. This is my struct:

typedef struct pair{
  int x;
  int y;
} PAIR;

And this is code where i use it and where the error occurs:

list<PAIR> openSet;
PAIR pair;
pair.x = xStart;
pair.y = yStart;
openSet.push_front(pair);

PAIR current;
for(PAIR p : openSet){
    if(fScores[p.x * dim + p.y] < maxVal){
         maxVal = fScores[p.x * dim + p.y];
         current = p;
    }
}

openSet.remove(current);

Error that i am getting is this:

 no match for ‘operator==’ (operand types are ‘pair’ and ‘const value_type’ {aka ‘const pair’})

Can you tell me how to fix this?

Aucun commentaire:

Enregistrer un commentaire