c++ - 为什么代码告诉我 vector 订阅超出范围

标签 c++

我为神经元网络编写了一个程序,一切正常,但这些代码行:

for (unsigned i = 0; i < Net.size() - 1; i++)
    {
        //Net is a vector of Layers, Layers are a vector of neurons, and Neurons are a Vector of weights and a double "values", the weights are also doubles
        for (unsigned l = 0; l < Net[i].size(); i++)
        {


            for (unsigned k = 0; k < Net[i][l].weights.size(); k++)
            {
                Net[i + 1][k].value = sigmoid(Net[i + 1][k].value);

                Net[i+1][k].value += Net[i][l].value* Net[i][l].weights[k];


            }

        }

    }

执行错误Vector subscribting out of range,我尽力了,但找不到错误

最佳答案

你有这个错误

for (unsigned l = 0; l < Net[i].size(); i++)

应该是

for (unsigned l = 0; l < Net[i].size(); l++)

使用名为 l 的变量确实不是一个好主意, 很容易误认为 i1 .

关于c++ - 为什么代码告诉我 vector 订阅超出范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56882920/

相关文章:

c++ - 使用 Boost 的 C++ 中的正则表达式

c++ - travis 构建失败说找不到 -lboost_system

c++ - "source code"和 "translation unit"之间有什么特别的区别吗?

C++ 在 while 循环中使用 switch 时输出相同

c++ - 查找数组中的最大值

c++ - 如何将此代码重写为 sse 内在函数

c++ - 智能指针 - 为什么使用它们,以及使用哪个?

Visual Studio 2008 的 C++ 语法突出显示?

c++ - 通用 lambda 的熟悉模板语法

c++ - 使用 boost::python 将回调从 python 传递到 c++