c++ type conversion
I have a function in C- code based application as given below:
void MyFunction(short count, double (*points)[2])
I am calling this function with the below parameter types:
MyFunction(count, poly_pts);
short count
double *poly_pts
Getting compiler error:
cannot convert parameter 2 from 'double *' to 'double (*)[2]'
I have to pass in the same manner as per the old code. C-cod开发者_如何学Ce doesn't give any error but c++ compiler gives.
Have anyone any ideas how to convert double pointer to two dimension double pointer?
The function expects a pointer to an array of 2 double
s, you only give it a single pointer.
Call it like this:
short count;
double points[2];
MyFunction(count, &points);
double (*points)[2]
is a pointer to an array of 2 elements. What you are passing to the function is actually just a pointer to double. If you want the call to work, you have to actually have an address to an array of 2 doubles. Something like this:
double array[2];
myFun(&array);
Change the function signature to take double*
(and possibly another parameter of type size_t
to indicate the size) or pass an appropriate value to your original function. Note that dynamic allocation of an array returns just a pointer, not a real array.
精彩评论