0

我需要用 c++/cli 中的另一个列表填充集合,所以当我尝试这样做时出现错误的问题

错误 C2664: 'SpaceClaim::Api::V10::InteractionContext::Selection::set' : 无法将参数 1 从 'System::Collections::Generic::ICollection ^' 转换为 'System::Collections::Generic: :ICollection ^'

这里是代码

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 
4

1 回答 1

2

问题是你试图从 to 投射ICollection<DesignEdge^>^ICollection<IDesignEdge^>^这是不安全的。您应该做的是IDesignEdge从一开始就进行操作:

auto newEdges = gcnew List<IDesignEdge^>();
于 2013-04-26T10:04:39.603 回答