I'm doing a problem of A * and I need to save the father and then print the route. Everything works correctly until I ask the parent node in the printing method and it gives me this error:
"error.EXC_BAD_INSTRUCTION (code = EXC_I386_INVOP, subcode = 0x0)"
I leave you all the pieces where this variable appears.
class node{
private:
node *padre;
vector<vector <string>>situacion;
int profundidad;
int g = 0;
int h = 0;
int f = 0;
string paso;
public:
node getPadre(){
return *padre;
}
void setPadre(node newPadre){
padre = &newPadre;
}
};
// ...
newNode.setPadre(nodo); //Donde "nodo es una variable de la clase node"
// ...
node itNode = itNode.getPadre(); // donde it node
The problem is that I save the nodes in a vector<nodes>
and reorganize it with sort in each iteration, with which the memories change, and therefore when trying to access the parent node, it is not there.
Do you know if there is any way to do a sort with a vector<*node>
?
Many thanks in advance to all who answer or try.