Original Post
So I have this function that recursively flows through a tree of vectors of pointers to Locations. Notice the reference parameter int&total
[source lang="cpp"]int score(Location* locationToScore, int&total){
total++;
int n = locationToScore->explored?1:0;
for (int i=0; isubLocations.size(); i++) n += score(locationToScore->subLocations, total);
return n;
}[/source]
I call this function like this:
[source lang="cpp"]int total = 0;
cout << score(sol, total) << "/" << total;[/source]
But it keeps displaying the total as 0.
Just to make sure I was doing it right I made a simpler program to test it and it works fine in the test program but I can't see a difference:
Test program:
[source lang="java"]#include
using namespace std;
int testFunction(int x, int&y){
y++;
if (x==0) return 1;
else return 1 + testFunction(x-1, y);
}
int main(){
int y = 3;
cout << testFunction(3, y);
cout << y;
}[/source]
[source lang="cpp"]int score(Location* locationToScore, int&total){
total++;
int n = locationToScore->explored?1:0;
for (int i=0; i
return n;
}[/source]
I call this function like this:
[source lang="cpp"]int total = 0;
cout << score(sol, total) << "/" << total;[/source]
But it keeps displaying the total as 0.
Just to make sure I was doing it right I made a simpler program to test it and it works fine in the test program but I can't see a difference:
Test program:
[source lang="java"]#include
using namespace std;
int testFunction(int x, int&y){
y++;
if (x==0) return 1;
else return 1 + testFunction(x-1, y);
}
int main(){
int y = 3;
cout << testFunction(3, y);
cout << y;
}[/source]