У меня есть проект CLI, который использует маршал для преобразования String ^ в std :: string.
По какой-то причине, когда я включаю заголовок, я получаю эти ошибки компиляции, которые я, кажется, не понимаю.
Даже когда я не обращаюсь к marshal_as, я все равно получаю ошибки компиляции.
Я посмотрел онлайн, чтобы не помочь.
Может быть, вы можете помочь?
Код:
#include <msclr\marshal_cppstd.h>namespace ConnectionWrapper
{
inline std::string ToStdString(System::String^ str)
{
return msclr::interop::marshal_as<std::string>(str);
}
inline System::String^ ToCliString(const std::string std)
{
return msclr::interop::marshal_as<System::String^>(std);
}
}
Ошибки компиляции:
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.15.26726\include\msclr\marshal.h(222): error C3861: '_This_conversion_is_not_supported': identifier not found
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.15.26726\include\msclr\marshal.h(224): note: see reference to class template instantiation 'msclr::interop::error_reporting_helper<_To_Type,_From_Type,false>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.15.26726\include\msclr\marshal.h(233): error C3861: '_This_conversion_requires_a_context': identifier not found
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.15.26726\include\msclr\marshal.h(235): note: see reference to class template instantiation 'msclr::interop::error_reporting_helper<_To_Type,_From_Type,true>' being compiled
Я решил проблему .. хотя я не очень понимаю, как. — Я отключил / разрешительный флаг — и все построено нормально
Большое спасибо за это предложение, я только столкнулся с той же самой проблемой.
Отключение /permissive
Флаг решил это. Кстати, я заметил, что флаг для C ++ CLR Empty Project для Windows выключен (/ SUBSYSTEM: WINDOWS), в то время как консольный проект Windows имеет его (VS 2017 / .Net 4.7).