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

&& : Cannot use this indirection on type '_Ty'

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

错误

&& : Cannot use this indirection on type '_Ty' with [ _Ty=System::String^ ]

是否可以转换?

convert.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();

convert.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^>

convert.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;

}

convert.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();