views:

462

answers:

2

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.

+4  A: 

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.

Reed Copsey
A: 

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.

Ed Woodcock