c++ advertizer: expected primary-expression before ‘>’ token

asked 2020-08-01 18:35:12 -0600

azerila gravatar image

I have a script where there is a subscriber which is implemented like the following:

sub_setpoint_ = this->nh_->subscribe("controllerReference", 1,
    &CartesianImpedanceControllerROS<ROBOT, COMPENSATE_GRAVITY>::setpointCallback, this,

and I would like to also make a publisher inside it. What I tried was to write something rather similar to the above subscriber:

 pub_setpoint_status_   = this->nh_->advertise<std_msgs::String>("set_point_status", 1);

However, this gives me the error:

 error: expected primary-expression before ‘>’ token
       pub_setpoint_status_   = this->nh_->advertise<std_msgs::String>("set_point_status", 1);

which with my basic c++ experience is unclear what the problem might be. Does anyoone know what I should do?

msgs::String>("set_point_status", 1);

edit retag flag offensive close merge delete



Have you #included the std_msgs/String.h header in the compilation unit in which you're trying to use the type?

gvdhoorn gravatar image gvdhoorn  ( 2020-08-02 04:57:42 -0600 )edit

@gvdhoorn yea I have done so with #include <std_msgs/String.h> and since in the same script declaring std_msgs::String msg; compiles with no problem I assume the include works.

azerila gravatar image azerila  ( 2020-08-02 06:01:07 -0600 )edit

Did you change your cmakelist c++ compiler version? ( add_compile_options(-std=c++11) )

Teo Cardoso gravatar image Teo Cardoso  ( 2020-08-03 15:42:41 -0600 )edit