I have a problem when I try to pass an array pointer (which contains the parameters needed by some functions in my program) to a structure, which then needs to be passed to these functions. GSL, for example, wants me to pass parameters this way.
An example of a small program is as follows:
#include <iostream>
using namespace std;
struct myparams
{
double * a;
double ** b;
};
int main()
{
double c[10] = {0,1,2,3,4,5,6,7,8,9};
double d[4][3] = {{1,2,3},{4,5,6},{7,8,9},{10,11,12}};
double** e = new double*[4];
for (int i = 0; i < 4; i++) {
e[i] = new double[3];
}
myparams params;
params.a = c;
for (int i = 0; i < 10; i++) {
cout << params.a[i] << endl;
}
params.b = d;
params.b = e;
delete[] e;
}
What is the problem with
params.b = d
The compiler complains about "cannot convert 'double[4][3]' to 'double**' in assignment"or something like that (translation from German).
source
share