C++ cli 无法从Icollection转换为Icollection c/cli
我需要用c++/cli中的另一个列表填充集合,因此,当我尝试这样做时,出现了一个错误 错误C2664:“SpaceClaim::Api::V10::InteractionContext::Selection::set”:无法将参数1从“System::Collections::Generic::ICollection^”转换为“System::Collections::Generic::ICollection^” 这是密码C++ cli 无法从Icollection转换为Icollection c/cli,c++-cli,C++ Cli,我需要用c++/cli中的另一个列表填充集合,因此,当我尝试这样做时,出现了一个错误 错误C2664:“SpaceClaim::Api::V10::InteractionContext::Selection::set”:无法将参数1从“System::Collections::Generic::ICollection^”转换为“System::Collections::Generic::ICollection^” 这是密码 List<DesignEdge^> ^newEdges =
List<DesignEdge^> ^newEdges = gcnew List<DesignEdge^>();
for each (DesignEdge^edge in onecopiedBody->Edges)
{
if (!edges->Contains(edge))
{
newEdges->Add(edge);
}
}
cstom->InteractionContext->Selection = safe_cast<ICollection<IDesignEdge^> ^>(newEdges); //error here
List^newEdges=gcnewlist();
对于每个(设计边^onecopiedBody中的边->边)
{
如果(!边->包含(边))
{
新建边->添加(边);
}
}
cstom->InteractionContext->Selection=safe_cast(newEdges)//这里出错
问题是您试图从ICollection^
强制转换到ICollection^
,这是不安全的。您应该从一开始就按照IDesignEdge
进行操作:
auto newEdges = gcnew List<IDesignEdge^>();
autonewedges=gcnewlist();