错误:无法将'array_type {aka boost :: multi_array}'转换为'double(*)[2]' [英] error: cannot convert ‘array_type {aka boost::multi_array}’ to ‘double (*)[2]’

查看:68
本文介绍了错误:无法将'array_type {aka boost :: multi_array}'转换为'double(*)[2]'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是c ++的初学者,并且是第一次使用boost库。

我有这个程序来解决微分方程:

I am a beginner in c++ and using boost library for the first time.
I have this program for solving a differential equation:

double rk2(double(*)[2], double, double, double, double(*)[2], double);
int main()
{// Create a 2D array that is n X 2
  typedef boost::multi_array<double, 2> array_type;
  typedef array_type::index index;
  array_type a(boost::extents[n][2]);

 // Create a 2D array that is n X 2
  typedef boost::multi_array<double, 2> array_type;
 typedef array_type::index index;
  array_type v(boost::extents[n][2]);



然后我有一些条件后跟..


Then I have some conditions followed by..

 while 
{ (....some condition...)
       tf = ti + dt;
       vf = rk2(a,ti,vi,tf, v, xi);
       xi = vf*dt+xi;
}
 return 0;
}



然后我定义我的功能


then i define my function

double rk2(double a[10000][2], double ti, double vi, double tf, double v[10000][2], double xi)
{ ....lines..
return vf;
}



我收到一条错误消息:


I''m getting an error message saying:

error: cannot convert ‘array_type {aka boost::multi_array<double,>}’ to ‘double (*)[2]’ for argument ‘1’ to ‘double rk2(double (*)[2], double, double, double, double (*)[2], double)’



请帮助我!


Please help me!

推荐答案

KarstenK是对的。



为了更清楚试试这个...



KarstenK is right.

To be clearer try this...

double rk2(array_type & a, double ti, double vi, double tf, double v[10000][2], double xi)
{ ....lines..
return vf;
}


using namespace std;
// Create a 2D array that is n X 2
typedef boost::multi_array<double, 2>two_d_array_type;
typedef two_d_array_type::index index;
// there is no need to name multi_array<double, 2> and index two times. We can do it here once and for all. Note that we defined it globally (outside any) function so that the new names that we have put are recognized by all functions
// I have put rk2 above main so that there is no need of an additional initial declaration
double rk2(two_d_array_type & a, double ti, double vi, double tf, two_d_array_type & v, double xi)
{...(lines)
return vf;
}

int main()
{ while 
{ (....some condition...)
       tf = ti + dt;
       vf = rk2(a,ti,vi,tf, v, xi);
       xi = vf*dt+xi;
}
 return 0;

}


这篇关于错误:无法将'array_type {aka boost :: multi_array}'转换为'double(*)[2]'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆