locked
Why Platform::Array<> dimension only support 1?

    Question

  • Why Platform::Array<> dimension only support 1? Can anybody tell me ?

    Monday, March 19, 2012 9:22 AM

Answers

All replies

  • Array should be 1 dimension 

    http://msdn.microsoft.com/en-us/library/bb983093.aspx

    Also in STL

    http://www.cplusplus.com/reference/stl/array/

    std::array<<var style="font-style:normal;color:#0000b0;">int</var>,10> myarray;  10 is its size


    NEU_ShieldEdge


    Tuesday, March 20, 2012 8:23 AM
  • You can use like this.

    Platform::Array<Platform::Array<int>^>^ arr = ref new Platform::Array<Platform::Array<int>^>(5);

    arr[0] = ref new Platform::Array<int>(10);

    ...

    Good luck.

    Tuesday, March 20, 2012 8:29 AM
  • I can't answer why because I wasn't involved in the design decision. I'll speculate that it was because there is no WinRT type which takes a multi-dimensional array. WinRT types are for crossing the ABI boundary. 

    As an aside, it looks like the template is setup to take a 2-D array in the future (non-informed speculation on my part, this isn't a feature promise). It seems to be limited to 1-D now:

    Compiles:

    auto oneD = ref new Platform::Array<int,1>(5);

    Doesn't compile:

    auto twoD = ref new Platform::Array<int,5>(5);
    error C3963: multi-dimensional array is not supported:

    Platform::Array is not dynamic and requires a length at creation. Interestingly, for template code, Jacks' code gives a good error message:

    Platform::Array<Platform::Array<int>^>^ arr = ref new Platform::Array<Platform::Array<int>^>();

    error C3964: jagged array is not supported

    So, 1D arrays are the only thing supported in this release. Please create a Connect bug with scenario details if you need 2D or multi-D arrays. More details and concrete use-cases make it more likely for features to get implemented.

    STL Vectors are often used for MD arrays and are fully supported in C++/CX:
    http://www.cplusplus.com/forum/articles/7459/

    PTR-based dynamic arrays as shown in the article are also supported.

    -Steve

    Tuesday, March 20, 2012 6:18 PM
    Moderator
  • That does not work and gives the error:: "jagged array is not supported"
    Monday, July 30, 2012 5:06 PM