我正在编写一个函数递归调用自身的代码。但是我陷入了无限循环,因为当函数返回时,它似乎没有返回到 while 循环的结束括号,而是返回到 int o 的定义位置。知道问题出在哪里吗?
ErrorCode QuadTree::PartialSearchHelper(Key *key, const uint64_t QInternal, Iterator ** records,int l[], int pow) {
try {
uint64_t temp=(&indexVec[QInternal])->Firstchild;
uint64_t ch = (&indexVec[QInternal])->Firstchild;
for (int i = 0; i < pow; i++) {
while (!(&indexVec[temp + l[i]])->isLeaf) {
int o= l[i]; //it returns here after finishing recursion call!!!!!!!!!
PartialSearchHelper(key, temp + l[i], records, l, pow);
}
((&indexVec[temp + l[i]]))->findPartial(key, records);
}
} catch (std::bad_alloc &e) {
throw (kErrorOutOfMemory);
} catch (ErrorCode &e) {
throw (e);
} catch (...) {
throw (kErrorGenericFailure);
}
return kOk;
}
最佳答案
你没有改变 while 内的任何值,所以它只是在较低级别的调用中重新启动 while
关于c++ - 无限递归 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9861197/