2013-05-12 89 views
0

我现在正在讨论这个话题。我试图使用VectorsIVectorsArrays是否可以在WinRT中用C++/CX创建一个数组数组?

Arrays在WinRT中的维数不能高于1,Vectors似乎不可能在公共场合使用。 (如果你能告诉我如何,请做!)和IVectors是接口,所以你不能使IVectorIVectors

是否有任何,我的意思是任何方式作出真正的二维阵列或数组的数组像它在C++/CLI是可能的?

(是的,我知道我可以模拟2点的尺寸与一个维数组,但我真的不希望这样做。)

+0

使用提供给您的类型从C++。 – 2013-05-12 21:09:22

+0

经过大量的研究,我发现有一个关键字internal,它使我能够在一种公共场合使用STL类型。所以最后,@HansPassant你的答案实际上解决了我的问题,尽管这不是问题的答案。 – iFreilicht 2013-06-20 11:48:39

+0

你能解释一下你怎么可以用“内部”在WinRT中使用STL类型 – 2016-10-02 18:38:34

回答

2

我用这个办法解决这个问题。不漂亮,但功能。

而不是创建矢量矢量创建对象的矢量。然后使用safe_cast访问包含Vector的Vector。

Platform::Collections::Vector<Object^ >^ lArrayWithinArray = ref new Platform::Collections::Vector<Object^ >(); 

//Prepare some test data 
Platform::Collections::Vector<Platform::String^>^ lStrings = ref new Platform::Collections::Vector<Platform::String^>(); 
lStrings->Append(L"One"); 
lStrings->Append(L"Two"); 
lStrings->Append(L"Three"); 
lStrings->Append(L"Four"); 
lStrings->Append(L"Five"); 

//We will use this to show that it works 
Platform::String^ lOutput = L""; 

//Populate the containing Vector 
for(int i = 0; i < 5; i++) 
{ 
    lArrayWithinArray->Append(ref new Platform::Collections::Vector<String^>()); 

    //Populate each Vector within the containing Vector with test data 
    for(int j = 0; j < 5; j++) 
    { 
     //Use safe_cast to cast the Object as a Vector 
     safe_cast<Platform::Collections::Vector<Platform::String^>^>(lArrayWithinArray->GetAt(i))->Append(lStrings->GetAt(j)); 
    } 
} 

//Test loop to verify our content 
for(int i = 0; i < 5; i++) 
{ 
    for(int j = 0; j < 5; j++) 
    { 
     lOutput += lStrings->GetAt(i) + L":" + safe_cast<Platform::Collections::Vector<Platform::String^>^>(lArrayWithinArray->GetAt(i))->GetAt(j) + ", "; 
    } 
} 
+0

我测试了这一点,它工作得很好!我认为对于小型媒介你不必关心效率。 我的问题的解决方案更像是使用STL向量。 不管怎样,这种解决方法似乎很好地做,当你真的需要通过ABI通过多维矢量。 – iFreilicht 2013-06-20 11:53:27

相关问题