2016-08-14 56 views
0

我有一个问题产生的std ::向量与字符串^对象:VISUALC++:字符串^和std :: vector的

std::vector<String^> vSometing; 

它提示错误:

'&&': cannot use this indirection on type 'System::String ^'

那么如何做String ^对象列表吗?

+0

*当您尝试编写interop代码时,一些*垃圾回收工作的基本理解非常重要。虽然编译器经常在你错误的时候说出你的指关节。它只能在找到对象根时才起作用,如System :: String引用。将它们存储在std :: vector中时无法工作,GC不知道该类型的外观,因此无法在对象引用的正确位置查找。你必须使用一个'std :: vector '来保持它的全部本地或'List ^'来保持它的全部管理。 –

回答

0

如果您更喜欢使用STL集合,则可以使用STL/CLR库。一种解决方案是ListVector使用new分配它的对象,但不能分配System::String^

使用List<String^>或将System::String^转换为std::string。 如何转换,看这topic

+0

在考虑推荐STL/CLR之前,请阅读[本文](http://www.codeproject.com/Articles/24206/A-look-at-STL-CLR-performance-for-linear-container)。 –