Can we change the value of *y
in void function(const int*& x )
when y
(i.e int*y= new int
) is passed as an argument to function()
?
If anyone could put it in words it would be great. Please refer to the following code for a better comprehension of my question:
void DoWork(const int* &n)
{
*n = *n * 2; // will this change the value of *a?
}
int main()
{
int* a= new int;
DoWork(a);
}
I was trying to understand a program where I came across a similar syntax. Have a look at a snippet from that program:
void segmentTable(const pcl::PointCloud<pcl::PointXYZRGB>::Ptr& cloud,
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr& seg_cloud){
double z_min = -5, z_max = 0;
pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients);
pcl::PointIndices::Ptr inliers (new pcl::PointIndices);
// Create the segmentation object
pcl::SACSegmentation<pcl::PointXYZRGB> seg;
// Optional
seg.setOptimizeCoefficients (true);
// Mandatory
seg.setModelType (pcl::SACMODEL_PLANE);
seg.setMethodType (pcl::SAC_RANSAC);
seg.setDistanceThreshold (0.01);
seg.setInputCloud (cloud);
seg.segment (*inliers, *coefficients);
// Project the model inliers
pcl::ProjectInliers<pcl::PointXYZRGB> proj;
proj.setModelType (pcl::SACMODEL_PLANE);
// proj.setIndices (inliers);
proj.setInputCloud (cloud);
proj.setModelCoefficients (coefficients);
proj.filter (*seg_cloud);
/* Create Convex Hull to segment everything above plane */
pcl::ConvexHull<pcl::PointXYZRGB> cHull;
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_hull (new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::PointIndices::Ptr hull_inliers (new pcl::PointIndices);
cHull.setInputCloud(seg_cloud);
cHull.reconstruct(*cloud_hull);
cHull.setDimension (2);
if (cHull.getDimension () == 2){
pcl::ExtractPolygonalPrismData<pcl::PointXYZRGB> prism;
prism.setInputCloud (cloud);
prism.setInputPlanarHull (cloud_hull);
prism.setHeightLimits (z_min, z_max);
prism.setHeightLimits (z_min, z_max);
prism.segment (*hull_inliers);
}
pcl::ExtractIndices<pcl::PointXYZRGB> extract_indices;
extract_indices.setInputCloud(cloud);
extract_indices.setIndices(hull_inliers);
extract_indices.setNegative(true);
extract_indices.filter(*cloud);
}
void int main(){pcl::PointCloud<pcl::PointXYZRGB>::Ptr temp_cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::fromPCLPointCloud2(pcl_pc2,*temp_cloud);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr seg_cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
passThroughFilter(temp_cloud);
segmentTable(temp_cloud, seg_cloud);}
This code does change the values in temp_cloud and seg_cloud.