我在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-> Add(ti)上看到了错误,
我了解错误,但不确定如何纠正。
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示例。
最佳答案
您缺少两个^
:
List<BatchMergeInterface::TrimInformation^> ^til = gcnew List<BatchMergeInterface::TrimInformation^>();