如何将 double* 转换为数组(6)
我有一个返回 6 个双精度数数组的函数。
double* Validation();
我想在托管代码中转换这个返回值。
array<double>^ validationPosition = gcnew array<double>(6);
validationPosition = Validation();
我收到此错误:
error C2440: '=' : cannot convert from 'double *' to 'cli::array<Type> ^'
我应该怎么做?
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您希望将其放在托管数组中,则需要将其复制到该数组中。 本机 double* 数组不能直接用作托管数组。
您可以使用 Marshall::Copy 来复制它,或者只是循环遍历您的 6 个值。
您还需要(可能)删除[]您的返回值,因为听起来它正在为您的validation()例程分配一个内部数组。
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.
您可以编写一个函数,迭代原始 double* 中的每个变量,并将值放入 cli::array 中的相关容器中,然后返回新数组。
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.