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

Error: 'std_srvs::Empty' is not a namespace

asked 2016-12-21 07:40:43 -0600

jolly gravatar image

Hey everyone,

I'm currently working through "A Gentle Introduction to ROS" and in the chapter about services the following example is shown:

bool toggleForward(std_srvs::Empty::Request &request, std_srvs::Empty::Response &response){...}

Now I don't want to write the std_srvs::Empty:: all the time and I tried the following:


using std_srvs::Empty::Request;
using std_srvs::Empty::Response;                                                                     

bool toggleForward(Request &request, Response &response){...}

But now I'm getting the following errors:

error: ‘std_srvs::Empty’ is not a namespace
 using std_srvs::Empty::Request;
                        ^

error: ‘std_srvs::Empty’ is not a namespace
 using std_srvs::Empty::Response;
                        ^
error: ‘Request’ was not declared in this scope
 bool toggleForward(Request &request, Response &response)
                    ^
 error: ‘request’ was not declared in this scope
 bool toggleForward(Request &request, Response &response)
                             ^
 error: ‘Response’ was not declared in this scope
 bool toggleForward(Request &request, Response &response)
                                      ^
error: ‘response’ was not declared in this scope
 bool toggleForward(Request &request, Response &response)
                                                ^

I don't understand what's happening here. For example, the following works:

using std::cout;

What is the difference between those two?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2016-12-21 08:11:22 -0600

gvdhoorn gravatar image

updated 2016-12-21 08:12:58 -0600

std is a namespace. But std_srvs::Empty is a type (in the std_srvs namespace), not a namespace itself, so you can't bring Request or Response out by a using declaration.

See this random post on SO that deals with the same issue.

edit flag offensive delete link more

Comments

And just to clarify: this is obviously not a ROS issue, but a general C++ misunderstanding.

gvdhoorn gravatar image gvdhoorn  ( 2016-12-21 08:14:01 -0600 )edit

I just found the header file for the Empty type and now it's completely obvious for me as well. Thank you.

jolly gravatar image jolly  ( 2016-12-21 08:50:24 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-12-21 07:40:43 -0600

Seen: 1,134 times

Last updated: Dec 21 '16