我具有以下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.
我在这里做什么错了?