c++ - 无限递归 C++

标签 c++ recursion

我正在编写一个函数递归调用自身的代码。但是我陷入了无限循环,因为当函数返回时,它似乎没有返回到 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/

相关文章:

C++ 可变参数宏和模板

javascript - jQuery 与普通 javascript : differences between append and appendChild when building DOM tree

python - 递归 Python 函数削弱 Django 站点性能

c++ - 递归函数不返回指定值

c++ - 函数返回错误值

c++ - 带有 cppwinrt 库的 Toast 通知 Windows 10

c++ - 使用模板解决了多重定义

c++ - 如何使用 C++ 将文本文件的不同部分上传到不同的数组

recursion - 在golang中创建数字组合的递归函数

c++ - 为什么 libstdc+ +'s std::vector' 的 ctor 实现不会导致内存泄漏?