我有一個問題產生的std ::向量與字符串^對象:VISUALC++:字符串^和std :: vector的
std::vector<String^> vSometing;
它提示錯誤:
'&&': cannot use this indirection on type 'System::String ^'
那麼如何做String ^對象列表嗎?
我有一個問題產生的std ::向量與字符串^對象:VISUALC++:字符串^和std :: vector的
std::vector<String^> vSometing;
它提示錯誤:
'&&': cannot use this indirection on type 'System::String ^'
那麼如何做String ^對象列表嗎?
如果您更喜歡使用STL集合,則可以使用STL/CLR庫。一種解決方案是List
。 Vector
使用new分配它的對象,但不能分配System::String^
。
使用List<String^>
或將System::String^
轉換爲std::string
。 如何轉換,看這topic。
在考慮推薦STL/CLR之前,請閱讀[本文](http://www.codeproject.com/Articles/24206/A-look-at-STL-CLR-performance-for-linear-container)。 –
*當您嘗試編寫interop代碼時,一些*垃圾回收工作的基本理解非常重要。雖然編譯器經常在你錯誤的時候說出你的指關節。它只能在找到對象根時才起作用,如System :: String引用。將它們存儲在std :: vector中時無法工作,GC不知道該類型的外觀,因此無法在對象引用的正確位置查找。你必須使用一個'std :: vector'來保持它的全部本地或'List ^'來保持它的全部管理。 –