2013-04-26 36 views
0

我需要填寫一個集合在C另一個列表++/CLI所以這個問題,當我嘗試這樣做,我得到一個錯誤不能自ICollection轉換爲ICollection的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 

回答

2

的問題是,你想投的ICollection<DesignEdge^>^ICollection<IDesignEdge^>^,這是不安全的。你應該做的是從IDesignEdge開始運作:

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