I am a beginner as comes to working with iterators and want to iterate through names of my points printing them out. I do not know how to access them, help me out please with an idea. My approach looks like this:
set<Point::Ptr> points = world->getPoints(); // have set of pointers to Point
Point::CPtr myPoint = *points.begin(); // dereferenced iterator to the first element
Point::CPtr lastPoint = *points.rbegin(); //dereferenced iterator to the last valid element
for(set<Point::Ptr>::iterator it = *points.begin(); it != points.end(); it++) {
ROS_INFO("points are: %s: ", myPoint.get()->getName().c_str());
}
Normally for iterator in a loop it shall be set to the first element of the set. But since set contains pointers and I want to be able to call functions available for objects inside those pointers, I tried this way. It works for a one only element like that, giving me desired name:
ROS_INFO("myPoint pointer gives %s: ", myPoint.get()->getName().c_str());
EDIT: typedef boost::shared_ptr CPtr;