C++ question
-
If I have an array: double xcoord[80]; I can pass it to a function and the function can receive it as a pointer... void AcceptArray(double* ) but how do I write the function prototype if that array were multidimensional, say -- xcoord[80][10]
Send it in as you would with a single dimensional array: void AcceptArray(double *array) but when you use it inside of your function, calculate the index that the two values would point to: // access array[x][y], array[(y * width) + x ] where width is the number of columns, or x values in one row.
Checkout my Guide to Win32 Paint for Intermediates
-
If I have an array: double xcoord[80]; I can pass it to a function and the function can receive it as a pointer... void AcceptArray(double* ) but how do I write the function prototype if that array were multidimensional, say -- xcoord[80][10]
-
Send it in as you would with a single dimensional array: void AcceptArray(double *array) but when you use it inside of your function, calculate the index that the two values would point to: // access array[x][y], array[(y * width) + x ] where width is the number of columns, or x values in one row.
Checkout my Guide to Win32 Paint for Intermediates
okay, I have this array: double x_coord1[80][10]; this is one of my function prototypes: void NewCoordinates(double* xcoord1, double* ycoord1, int global_numcoord1, double* x_coord1, double* y_coord1); and when I call on the function like so: NewCoordinates(xcoord1, ycoord1, global_numcoord1, x_coord1, y_coord1); I get this error: C:\Windows\Desktop\QE2 heart program\TestGLView.cpp(460) : error C2664: 'NewCoordinates' : cannot convert parameter 4 from 'double [80][10]' to 'double *' what am I doing wrong?
-
If I have an array: double xcoord[80]; I can pass it to a function and the function can receive it as a pointer... void AcceptArray(double* ) but how do I write the function prototype if that array were multidimensional, say -- xcoord[80][10]
-
okay, I have this array: double x_coord1[80][10]; this is one of my function prototypes: void NewCoordinates(double* xcoord1, double* ycoord1, int global_numcoord1, double* x_coord1, double* y_coord1); and when I call on the function like so: NewCoordinates(xcoord1, ycoord1, global_numcoord1, x_coord1, y_coord1); I get this error: C:\Windows\Desktop\QE2 heart program\TestGLView.cpp(460) : error C2664: 'NewCoordinates' : cannot convert parameter 4 from 'double [80][10]' to 'double *' what am I doing wrong?
I am sorry, I was writing a test program to make sure that I gave you good advice, and I was distracted in the middle. When I came back to write my message to you, I assumed that the code that I got was working. Woods13 gives the correct way to do it: double x[][80] or double **x The way that I suggested is for dynamic arrays that are declared like this: double x[20 * 80]; then your array is one dimensional.
Checkout my Guide to Win32 Paint for Intermediates