There is a stack overflow from my code I do not really know what is causing it. Parent is a fixed array like 14.
protected:
int* parent = new int[14];
int size = 14;
int Tree::level(int i) {
int count = 0;
for (int j = 0; j < size; j++) {
if (parent[i] == -1) {
count = 1;
} else {
count = level(i) + 1; //this is causing the stack Overlow
}
}
return count;
}
parent[i]isunsigned, this could be bad. Consider putting a breakpoint on thecount = 1condition to be sure. It'd be nice to knowsizetoo... Please add a runable example and make sure you have no warnings when compiling.14is not an array, so what did you mean? Anyway, why do you use recursion there at all?level(i+1)?parentarray? The value ofsize? Afaik, instantiating 2ints will overflow your stack with too much recursion.inever change, so it should be calling the same thing forever