I'm relatively new to C++ so please excuse any oversights.
I have a custom Node class that contains an id and a position. In the main portion of my code, I created a vector, std::vector<Node>candidateNodes
, and pushed a bunch of newly created nodes in.
I have a function, expandCandidateNode, that takes in one of the nodes from the vector of candidateNodes as well as the vector itself and does some stuff with it:
expandCandidateNode(Node &candidateNode, std::vector<Node> &candidateNodes)
At the end of the function, I want to remove the candidateNode from my vector of candidateNodes. I tried using the solution from this stackoverflow question, which looks something like this:
candidateNodes.erase(std::remove(candidateNodes.begin(), candidateNodes.end(), candidateNode), candidateNodes.end());
However, when I tried building the project, I got the following error:
1>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\algorithm(1815): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'Node' (or there is no acceptable conversion)
I took a closer look, and found the error originated from the template function remove in the algorithm class. I'm not really sure what to do from here. My intention was to have the candidateNodes vector search for the node with the same reference as the candidateNode (basically ensuring they are the same object in memory), and removing it, but it seems like the == operator isn't able to compare their references? I may be misunderstanding something. If someone could clarify how I can properly remove a node from a vector, given its reference, it would be much appreciated. Thanks.