如何将 double* 转换为数组(6)

发布于 2024-07-17 15:31:15 字数 389 浏览 2 评论 0原文

我有一个返回 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放手` 2024-07-24 15:31:15

如果您希望将其放在托管数组中,则需要将其复制到该数组中。 本机 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.

冬天的雪花 2024-07-24 15:31:15

您可以编写一个函数,迭代原始 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文