简体   繁体   English

如何从std :: vector构造Platform :: Array

[英]How to construct a Platform::Array from a std::vector

I thought it works like this 我以为它像这样

std::vector<char> array;
Platform::Array<char>^ data = ref new Platform::Array<char>(array, array.size());

but says "no instance of constructor matches the argument list" 但说“没有构造函数的实例匹配参数列表”

You should send pointer to constructor of Platform::Array and std::vector is class, not array. 您应该将指针发送到Platform :: Array的构造函数,而std::vector是类,而不是数组。

Platform::Array<char>^ data = ref new Platform::Array<char>(array.data(), 
array.size());

If C++11 is enabled, or 如果启用了C ++ 11,或者

Platform::Array<char>^ data = ref new Platform::Array<char>(&array[0], 
array.size());

if not (it is UB to access first element in empty vector, so I have no idea about how we can get access to underlying array before C++11, when vector is empty). 如果不是的话(在UB中访问空向量中的第一个元素是UB,所以我不知道在向量为空时如何在C ++ 11之前访问底层数组)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM