Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ cli 无法从Icollection转换为Icollection c/cli_C++ Cli - Fatal编程技术网

C++ cli 无法从Icollection转换为Icollection c/cli

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 =

我需要用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 
List^newEdges=gcnewlist();
对于每个(设计边^onecopiedBody中的边->边)
{
如果(!边->包含(边))
{
新建边->添加(边);
}
}
cstom->InteractionContext->Selection=safe_cast(newEdges)//这里出错

问题是您试图从
ICollection^
强制转换到
ICollection^
,这是不安全的。您应该从一开始就按照
IDesignEdge
进行操作:

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