与局部变量关联的堆栈存储器地址

时间:2018-10-25 19:42:55

标签: c++

我具有以下C ++函数,试图返回float的数组:

float* get_my_weights(int e, int n, float a, float b) {
    float weights[10] = {1};
    weights[0] = e + n + a + b;
    return weights;
};

在编译期间,出现以下错误:

myFunction:4:12: error: address of stack memory associated with local variable 'weights' returned[-Werror,-Wreturn-stack-address]
    return weights;
           ^~~~~~~
1 error generated.

我在这里做什么错了?

0 个答案:

没有答案