我基本上想做的是编写一个函数,它可以采用长度为 n 的数组,并制作一个长度为 n-2 的数组。这是我到目前为止的代码:
float* comp_arr(float vals[], int arr_size, float scale, float dim){
int arr_dim = (int)(arr_size+1-2*scale);
float curvs[arr_dim];
for(int i = scale; i < sizeof(vals)-scale+1; i++){
float cur = comp_cur((i-scale)*dim, vals[i-1], i*dim, vals[i], (i+scale)*dim, vals[i+1]);
int new_index = (int)(i-scale);
curvs[new_index] = cur;
printf("%f\n",cur);
}
return curvs;
}
我一直在这样的主函数中调用它:
main(){
float vals [] = {2,3,6,1,7};
float *curvs = comp_arr(vals,5,1.0,1.0);
}
但我收到此错误:
comp.cpp: In function ‘float* comp_arr(float*, int, float, float)’:
comp.cpp:35:8: warning: address of local variable ‘curvs’ returned [enabled by default]
/tmp/ccrDJjYq.o: In function `comp_arr(float*, int, float, float)':
comp.cpp:(.text+0x590): undefined reference to `__cxa_end_cleanup'
/tmp/ccrDJjYq.o:(.ARM.extab+0xc): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
我对 C++ 很陌生,我做错了什么??????