I have a recursive function that has a parameter that is a reference to a 2D matrix of object pointers. My simple question is in what format do I pass that within the function so that it would work?
I wrote this code purely for example to pass my point along and in no way represents my intended use of recursion.
This code checks for a 0 object ID value in a diagonal line through the matrix to 255,255. Then prints 0 or -1.
typedef object* m256x256[256][256];
int x = 0;
int y = 0;
int isThereZero(m256x256 & m){
if(m[x][y]->getID() == 0){ // Each object has an ID value
return 0;
}
x++;
y++;
if(x==256){
return -1;
}
return isThereZero(/*I need to pass M byref again... what do I put here?*/);
}
int main{
object* M[256][256];
/* Initialization Code */
cout << isThereZero(M);
return EXIT_SUCCESS;
}
So that by the 256th recursion m is still the same reference to M
Specific question: How do I format this to get it to compile:
int isThereZero(m256x256 & m){
return isThereZero(/*I need to pass M byref again... what do I put here?*/);
}
m256x256mitself. It compiles fine for me. It also looks like that's how you intended your algorithm to work.