Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am a beginner in c++ and using boost library for the first time.
I have this program for solving a differential equation:
C#
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..
C#
 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
C#
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:
HTML
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!
Posted
Updated 28-May-13 12:09pm
v3
Comments
KarstenK 28-May-13 8:49am    
using a fixed size for function parameters is always a bad idea.

Prefer using owned defined data types or second best arrays with variable dimension.

Rule of thumb: using defined data types helps a to avoid a mob of bugs. ;-)
[no name] 29-May-13 5:35am    
I'm getting another error then, error: invalid types ‘double[int]’ for array subscript this error is coming while giving value of array to another variable: int l; eita = a[l][0]; what to do?

KarstenK is right.

To be clearer try this...

C++
double rk2(array_type & a, double ti, double vi, double tf, double v[10000][2], double xi)
{ ....lines..
return vf;
}
 
Share this answer
 
Comments
[no name] 29-May-13 2:36am    
I'm getting another error then,
error: invalid types ‘double[int]’ for array subscript
this error is coming while giving value of array to another variable:
int l;
eita = a[l][0];
what to do?
KarstenK 29-May-13 7:22am    
You need to use matchtng types. For that reason you should carefully define the interface. Use the approbiate type.
C#
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;

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900