double sum(double **sum)
{
double result=0.0;
int k,l;
for(k=0;k<N;k++)
for(l=0;l<M;l++)
{
result+=sum[k][l]>0?sum[k][l]:(-sum[k][l]);
}
return result;
}
double subsum(double **sub1,double **sub2)
{
double subresult=0.0;
int m,n;
for(m=0;m<N;m++)
for(n=0;n<M;n++)
{
subresult+=(sub1[m][n]-sub2[m][n])>0?(sub1[m][n]-sub2[m][n]):(sub2[m][n]-sub1[m][n]);
}
return subresult;
}
void main()
{
...................
error = subsum(us,vx)/sum(us);\\us,vx,vs,vy是定义的动态数组
error1 = subsum(vs,vy)/sum(vs);
error = error +error1;
..........................................
}
这个程序运行时老是有错误,实在搞不懂,请教高手给讲解一下关于二维动态数组的问题,以及二维指针和二维数组做参数传递的问题.
上面这个程序如果改怎么改呢??
这是提示的错误信息:
:\我的文档\program\lattice boltzmann code\正确程序(动态数组).cpp(493) : error C2664: 'subsum' : cannot convert parameter 1 from 'double *' to 'double [][51]'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\我的文档\program\lattice boltzmann code\正确程序(动态数组).cpp(493) : error C2664: 'sum' : cannot convert parameter 1 from 'double *' to 'double [][51]'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\我的文档\program\lattice boltzmann code\正确程序(动态数组).cpp(494) : error C2664: 'subsum' : cannot convert parameter 1 from 'double *' to 'double [][51]'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\我的文档\program\lattice boltzmann code\正确程序(动态数组).cpp(494) : error C2664: 'sum' : cannot convert parameter 1 from 'double *' to 'double [][51]'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
正确程序(动态数组).obj - 4 error(s), 0 warning(s)