c++ - Changing vector value causing seg fault -
i working on school project graphs , here doing depth first search down tree.
void wdigraph::depth_first(int v) const { static int firstv = -1; static bool *visited = null; if (firstv == -1) { firstv = v; vector<bool> visited(size); (int = 0; < size; i++) { visited[i] = false; cout << visited[i] << endl; } } cout << label[v]; visited[v] = true;
// visited[0] = true;
the first input value function 0 (v = 0) , crashes that. size = 5. can see @ end of code, have tried set visited true manually same seg fault. when remove attempts change visited, program runs how should without seg fault.
any ideas why can't modified? also, there more code have decided not provide unless necessary.
there 2 different variables named visited
in code. inside if
condition, visited
vector, outside block, on last line:
visited[v] = true;
visited
refers bool *visited = null
defined @ beginning of code. segfault occurs because you're trying dereference null pointer.
Comments
Post a Comment