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

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

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

ParkerRobert gravatar image

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

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

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

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


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 -0500 )edit

Question Tools



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

Seen: 845 times

Last updated: Jun 27 '21