【发布时间】:2014-08-07 09:49:10
【问题描述】:
在循环中,我需要调用一个参数类型为pcl::PointIndicesPtr 的函数。这实际上是一个boost::shared_ptr< ::pcl::PointIndices>。有没有办法做到这一点而不必复制基础数据?我只能通过使用make_shared 来工作,如果我理解正确,它会复制对象。
for (std::vector<pcl::PointIndices>::const_iterator it = cluster_indices.begin (); it != cluster_indices.end (); ++it)
{
pcl::PointIndicesPtr indices_ptr2 =boost::make_shared<pcl::PointIndices>(*it);
}
例如,这将在运行时崩溃:
for (std::vector<pcl::PointIndices>::const_iterator it = cluster_indices.begin (); it != cluster_indices.end (); ++it)
{
pcl::PointIndices test = *it;
pcl::PointIndicesPtr indices_ptr3(&test);
}
【问题讨论】:
-
当然会,你传递一个指向临时对象的指针,它在循环迭代或结束时被销毁......