Convert array<int^>^ to int*
how can I convert array<int^>^开发者_StackOverflow中文版
to int*
?
You cannot, at least not the simple way.
If you mean array<int>^
to int*, you can do following:
array<int>^ arr;
cli::pin_ptr<int> pArrayElement = &arr[0];
and then use classical pointer arithmetic over the pin_ptr
.
I think it will be hard to directly convert array<int^>^
into an int*
, because it is an array of references to ints, not an array of ints. There is no promises about the memory layout of the integers themselves, which is required in order to get them to a plain old C/C++ array.
I think that the easiest way to go is to make a copy of the array, pass it to f(int* input)
and then possibly copy the data back if it is modified by f.
Name of the array is the address of first element in the array.
int array[] = {1, 2, 3, 4, 5};
int* p = array;
精彩评论