I have the following c# and c++ pinvoke marshalling of 2d multidimensional array of type double matter I\'m trying to solve.
I\'ve reviewed the following hit to ge
This code:
*values = new double[*valuesOuterLen, *valuesInnerLen];
does not do what you think it does. (I shortened the variable names because they just complicate things.)
C++ inherits from C a lack of multi-dimensional arrays. What it does have is arrays of arrays, or arrays of pointers to arrays. In both cases you index these as array[firstIndex][secondIndex]
. You can't new
an array of pointers like that, you have to write something like:
double*** values; // Triple pointer! Ow!! *values is a pointer to
// (an array of) pointers to (arrays of) doubles.
*values = new double*[*valuesOuterLen];
for (size_t i=0; i
What you have actually invoked is the C++ comma operator, which evaluates and discards the first operand, and then evaluates the second operand. Crank your compiler warnings up; a good compiler will warn that the first operand has no side-effects.