我写了以下递归多项式乘法,但它给了我错误,代码在这里
#include<iostream>
#include<vector>
using namespace std;
#define N 4
float *mult(float p[],float q[],int n)
{
float pl[N/2],ql[N/2],ph[N/2],qh[N/2];
float t1[N/2],t2[N/2];
float r[2*N-2],rl[N],rm[N],rh[N];
int i,N2;
if(N==1)
{
r[0]=p[0]*q[0]; return (float *)r;
}
for(i=0;i<N/2;i++)
{
pl[i]=p[i];
ql[i]=q[i];
}
for(i=N/2;i<N;i++)
{
ph[i-N/2]=p[i];
qh[i-N/2]=q[i];
}
for(i=0;i<N/2;i++) t1[i]=pl[i]*ph[i];
for(i=0;i<N/2;i++) t2[i]=ql[i]*qh[i];
rm=mult(t1,t2,N/2);
rl=mult(pl,ql,N/2);
rh=mult(ph,qh,N/2);
for(i=0;i<N-1;i++) r[i]=rl[i];
r[N-1]=0;
for(i=0;i<N-1;i++) r[N+i]=rh[i];
for(i=0;i<N-1;i++)
r[N/2+i]+=rm[i]-(rl[i]+rh[i]);
return (float *)r;
}
错误是这些
(13): warning C4172: returning address of local variable or temporary
(28): error C2440: '=' : cannot convert from 'float *' to 'float [4]' There are no conversions to array types, although there are conversions to references or pointers to arrays
(29): error C2440: '=' : cannot convert from 'float *' to 'float [4]' There are no conversions to array types, although there are conversions to references or pointers to arrays
(30): error C2440: '=' : cannot convert from 'float *' to 'float [4]' There are no conversions to array types, although there are conversions to references or pointers to arrays
(36): warning C4172: returning address of local variable or temporary
我不明白什么是原因?请帮助我