Creating a multidimensional array in C++/CLI with an empty dimension size

安稳与你 提交于 2019-12-11 01:04:41

问题


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.

Original C#:

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

C++/CLI:

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

回答1:


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

These two are the same:

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

and so are these:

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

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);

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



来源:https://stackoverflow.com/questions/37163786/creating-a-multidimensional-array-in-c-cli-with-an-empty-dimension-size

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!