在C ++ / CLI中创建尺寸为空的多维数组 [英] Creating a multidimensional array in C++/CLI with an empty dimension size

查看:97
本文介绍了在C ++ / CLI中创建尺寸为空的多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将C#项目转换为C ++ / CLI项目。我碰到了这段代码,想验证我使用的是正确的C ++ / CLI语法。我很确定自己做错了,只是在要设置尺寸大小时设置参数。

I am working on converting a C# project to a C++/CLI project. I came across this code and wanted to verify that I am using the proper C++/CLI syntax. I am pretty sure I am doing it wrong, just setting parameters when I want to set the size of the dimensions.

原始C#:

public double[][] _ARRAY = new double[num][];

C ++ / CLI:

C++/CLI:

array<double, 2>^ _ARRAY = gcnew array<double, 2>{ {num}, {} };


推荐答案

这就是在C ++ /中创建多维数组的方式CLI。但是C#实际上根本不是多维数组。

That IS how you create a multidimensional array in C++/CLI. But the C# isn't actually a multidimensional array at all.

这两个是相同的:

/* C# */ public double[][] arrayOfArray;
/* C++/CLI */ array<array<double>^>^ arrayOfArray;

这些也是:

/* C# */ public double [,] array2D;
/* C++/CLI */ array<double,2>^ array2D;

真正的二维数组不能像您展示的那样是半尺寸的,只有在锯齿状数组(数组数组)。对于锯齿状数组,C ++ / CLI当然应该允许

A real two-dimensional array can't be half-dimensioned as you show, that's only possible with a jagged array (array of arrays). For the jagged array, C++/CLI should certainly allow

arrayOfArray = gcnew array<array<double>^>(num);

(就像您问题中的C#代码一样)是(最初为null)托管句柄的数组数组。

which is (just like the C# code in your question) an array of (initially null) managed handles to arrays.

这篇关于在C ++ / CLI中创建尺寸为空的多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆