Tutorial :How to convert a double* to an array(6)



Question:

I have a function that returns a array of 6 doubles.

double* Validation();  

I would like to cast this return value in managed code.

array<double>^ validationPosition = gcnew array<double>(6);  validationPosition = Validation();  

I get this error:

error C2440: '=' : cannot convert from 'double *' to 'cli::array<Type> ^'  

How should I do this?

Thanks.


Solution:1

If you want this to be in a managed array, you will need to copy it into the array. The native double* array will not be usable directly as a managed array.

You can use Marshall::Copy to copy this, or just loop through your 6 values.

You will also want to (probably) delete[] your return values, since it sounds like it's allocating an array internal to your validation() routine.


Solution:2

You could write a function that iterates through each variable in the original double* and puts the values into the relevant container in a cli::array, then return the new array.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »