无法从Icollection转换为Icollection c / cli

时间:2013-04-26 08:51:09

标签: c++-cli

我需要用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 

1 个答案:

答案 0 :(得分:2)

问题是你正试图从ICollection<DesignEdge^>^投射到ICollection<IDesignEdge^>^,这是不安全的。你应该做的是从一开始就以IDesignEdge的方式运作:

auto newEdges = gcnew List<IDesignEdge^>();