I ve got a problem with allocating cli::array in function.
I have this kind of object:
array<double>^ tmsr2;
now I want to allocate it in function so:
void allocate(array<double>^ tmsr2)
{
tmsr2=gcnew array<double>(100);
}
Now, tmsr2 in function gets allocated well but I lose the pointer when returning to main()
The problem is clear to me, just like if I want to allocate simple array “double *a”; I need to pass pointer to function so “&a” and then everything works fine. I just don’t know the syntax with managed arrays. Help much appreciated.
Peter
Since
array<double>is a managed type, you can use a managed tracking reference here, instead of a plain reference.Here’s my test app:
Output:
Of course, you could always switch your allocate function to return the newly allocated array, rather than taking it as a reference. That would be more in the managed style.