I am a beginner with C++ so please excuse my ignorance.
I am attempting to pass a dynamically created 2d array to a function.
The array the [3]x[variable] array is created like this.
//Create array for the transformed coords
double **transf;
transf = new double*[3];
for (int i=0;i<atoms;i++){
cout << i;
transf[i]=new double[atoms];
}
I declare the function and call it
void printdata(int, string*, double* , double*,double**);
int main (int argc, char **argv)
{
...
printdata(allatoms ,name, rot1, rot2, transf);
...}
Here is the function.
void printdata(int allatoms ,string* name[], double rot1[], double rot2[], double** transf[][]){
for (int i=0; i<allatoms; i++){
if (i==0){
cout << name[i];
for (int r1=0; r1<3; r1++){
printf(" %*.*f",15,8,rot1[r1] );
}
cout << endl;
}
if (i==1){
cout << name[i];
for (int r2=0; r2<3; r2++){
printf(" %*.*f",15,8,rot2[r2] );
}
cout << endl;
}
if (i>1){
cout << name[i];
for (int r3=0; r3<3; r3++){
printf(" %*.*f",15,8,transf[r3][i-2] );
}
cout << endl;
}
}
}
When I try to compile I get
rotation.cpp(225): error: parameter type involves pointer to array of unknown bound
void printdata(int allatoms ,string* name[], double rot1[], double rot2[], double** transf[][]){
rotation.cpp(244): error: expression must be a pointer to a complete object type
printf(" %*.*f",15,8,transf[r3][i-2] );
How can I pass this array?
I would just declare the variables as global variables but the size of the array is passed in an argument to the program.