我正在編寫一個函數以遞歸方式調用自己的代碼。但我陷入了一個無限循環,因爲它似乎當函數返回它不會返回到while循環的結束括號,但它返回到int o定義的位置..任何想法,問題可能是什麼?無限遞歸C++
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;
}
在某些情況下,這可能會導致堆棧溢出。 – 01100110 2012-03-25 15:12:42
「,但它返回到int o定義的地方..」哦,不,它不。 – 2012-03-25 15:14:03
爲什麼'(&indexVec [temp + 1 [i]]) - >',只要做'indexVec [temp + l [i]]。 – 2012-03-25 15:14:07