我在c ++中有以下内容
class TrimInfo
{
public:
std::string LineName;
std::string OrigImagePath;
double Width;
double Height;
};
typedef std::shared_ptr<TrimInfo> TrimInfoPtr;
void SomeFunction();
bool DoSomethingElse(std::vector<JunkInfoPtr> &junkinfo, int *count);
bool SetTrimInfo(std::string ModelName, std::string PieceName, std::vector<TrimInfoPtr> trimInfo);
我在C#代码中
namespace BatchMergeAPI
{
public partial class BatchMergeInterface
{
public struct TrimInformation
{
public string LineName;
public string OrigImagePath;
public double Width;
public double Height;
};
public bool SetTrimInfo(string ModelName, string PieceName, List<TrimInformation> trimInfo)
{
return true;
}
}
}
现在回到c ++代码中将信息传递给C#我已经完成了这个,但在til-&gt; Add(ti)上出现错误,其中说
BatchMergeWrapper.cpp(52):错误C2664:'void System :: Collections :: Generic :: List :: Add(BatchMergeAPI :: BatchMergeInterface :: TrimInformation)':无法从'BatchMergeAPI :: BatchMergeInterface转换参数1: :TrimInformation ^'to'BatchMergeAPI :: BatchMergeInterface :: TrimInformation'
我理解错误但不确定如何纠正。
bool BatchMergeWrapper::SetTrimInfo(std::string modelName, std::string pieceName, std::vector<TrimInfoPtr> trimInfo)
{
System::String^ mn = gcnew System::String(modelName.c_str());
System::String^ pn = gcnew System::String(pieceName.c_str());
List<BatchMergeInterface::TrimInformation> ^til = gcnew List<BatchMergeInterface::TrimInformation>();
for (unsigned i = 0; i < trimInfo.size(); ++i)
{
BatchMergeInterface::TrimInformation^ ti = gcnew BatchMergeInterface::TrimInformation();
ti->Height = trimInfo[i]->Height;
ti->Width = trimInfo[i]->Width;
ti->LineName = gcnew System::String(trimInfo[i]->LineName.c_str());
ti->OrigImagePath = gcnew System::String(trimInfo[i]->OrigImagePath.c_str());
til->Add(ti);
}
return _private->batchmergeAPI->SetTrimInfo(mn, pn, til);
}
感谢您提供任何帮助,我很想看看所有的List示例。