&&:不能在类型 '_Ty' 上使用此间接寻址



我想将std::list <std::string>转换为std::list<System::String^>,但出现错误

&

&:不能在类型"_Ty"上使用此间接寻址,[ _Ty=系统::字符串^ ]

可以转换吗?

转换.h

#pragma once
#include <list> 
#include <string>
#include <msclr/marshal.h>
__declspec(dllimport) std::list<std::string> x_browseCan();

__declspec(dllexport) std::list<System::String^> wrap_browse_can();

转换.cpp

#include "pch.h"
#include "cok_main.h"
std::list<System::String^> wrap_browse_can() {
std::list<std::string> temporary_list;
std::list<System::String^> object_list;
temporary_list = x_browseCan();
for (std::list<std::string>::iterator it = temporary_list.begin(); it != temporary_list.end(); it++) {
object_list.push_back(msclr::interop::marshal_as<System::String^>(*it));
}
}

如@madreflection所述,我将代码修复如下。列表必须System::Collections::Generic::List<System::String^>^而不是std::list<System::String^>

转换.cpp

#include "pch.h"
#include "cok_main.h"

System::Collections::Generic::List<System::String^>^ wrap_browse_can() {
std::list<std::string> temporary_list;
System::Collections::Generic::List<System::String^>^  object_list;
temporary_list = x_browseCan();
for (std::list<std::string>::iterator it = temporary_list.begin(); it != temporary_list.end(); it++) {
std::string asd = *it;
System::String^ my_string = gcnew System::String(asd.c_str());
object_list->Add(my_string);
//object_list.push_back(msclr::interop::marshal_as<System::String^>(asd));
}
return object_list;
}

转换.h

#pragma once
#include <list> 
#include <string>
#include <msclr/marshal.h>
__declspec(dllimport) std::list<std::string> x_browseCan();

__declspec(dllexport) System::Collections::Generic::List<System::String^>^ wrap_browse_can();

相关内容

  • 没有找到相关文章

最新更新