ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

What is the difference between ros::NodeHandle nh("") and just ros::NodeHandle nh?

asked 2021-06-27 03:41:07 -0600

ParkerRobert gravatar image

updated 2021-06-27 04:43:49 -0600

gvdhoorn gravatar image

I understand that ros::NodeHandle nh("~") is a private namespace and that ros::NodeHandle nh("/") is the global namespace but what exactly is the difference between ros::NodeHandle nh("") and ros::NodeHandle nh, are they the same thing?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2021-06-27 08:29:01 -0600

Mike Scheutzow gravatar image

You could easily answer this for yourself by looking at the c++ constructor in /opt/ros/melodic/include/ros/node_handle.h.

The answer is: Yes, nh and nh("") construct the identical object.

To help other people who need to read your code, you should use the first version.

edit flag offensive delete link more

Comments

That was a clear answer, the constructor is NodeHandle(const std::string& ns = std::string(), const M_string& remappings = M_string()) in /opt/ros/melodic/include/ros/node_handle.h, as you said. Leaving it empty will result in ns = std::string() and using nh("") would also result in an empty string. So effectively they are both the same

ParkerRobert gravatar image ParkerRobert  ( 2021-06-27 09:07:44 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2021-06-27 03:41:07 -0600

Seen: 989 times

Last updated: Jun 27 '21