X
xz
I wrote a function which looks like:
bool Xxx::findShortestPath(int xS, int yS, int xT, int yT,
vector<Vertex*> path) {
....
}
It meant to find a path, save the path in vector<Vertex*> path, and
pass the path back to the calling function.
And in some other function (say, main()), I called this function like:
int main() {
....
vector<Vertex*> path;
xxx.findShortestPath(0, 0, 9, 9, path);
// then print out the path
}
However, I just noticed that it failed to passed the path to the
main() function. That is, in the function findShortestPath(...), the
data has been loaded into *path*, but when it goes back to main(), all
data is lost.
I know this happens because of the memory management logic, but I am
not clear about how to fix this and get what I want.
Anybody gives some hints?
Thanks a lot!
bool Xxx::findShortestPath(int xS, int yS, int xT, int yT,
vector<Vertex*> path) {
....
}
It meant to find a path, save the path in vector<Vertex*> path, and
pass the path back to the calling function.
And in some other function (say, main()), I called this function like:
int main() {
....
vector<Vertex*> path;
xxx.findShortestPath(0, 0, 9, 9, path);
// then print out the path
}
However, I just noticed that it failed to passed the path to the
main() function. That is, in the function findShortestPath(...), the
data has been loaded into *path*, but when it goes back to main(), all
data is lost.
I know this happens because of the memory management logic, but I am
not clear about how to fix this and get what I want.
Anybody gives some hints?
Thanks a lot!