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

Cannot Declare Reference to tf2_msgs::TFMessage

asked 2016-11-02 09:36:16 -0500

ElizabethA gravatar image


I had a great callback function in a Gazebo plugin. I declared it with

void OnMsg(ConstVector3dPtr &msg)

and subscribed-to by my plugin's Load function with

subscriber = node->Subscribe("~/eb/vel_cmd", &MyPlugin::OnMsg, this);


Instead of subscribing to "~/eb/vel_cmd", I'm subscribing to "/tf", so I need to change the message type of the callback (MyPlugin::OnMsg) to tf2_msgs::TFMessage. I followed the convention of the question in the link below to create a constant pointer for a tf2_msgs::TFMessage message.

Following the positionCb callback declaration in that code, now my callback is declared with:

private: void OnMsg(const tf2_msgs::TFMessage::ConstPtr& &msg)

I'm getting all kinds of compiling errors, but the biggest problem appears to be "Cannot declare reference to tf2_msgs::TFMessage_<std::allocator<void> >::ConstPtr& {aka class boost::shared_ptr<const tf2_msgs::tfmessage_<std::allocator<void="">>&}' (picture below).

Any ideas on what I'm doing incorrectly?

Compiling Errors:

image description

edit retag flag offensive close merge delete


private: void OnMsg(const tf2_msgs::TFMessage::ConstPtr& &msg) Do you need two ampersands here? Cannot declare reference to ... which is not a typedef or a template type argument I'm no c++ wizard, but it sounds like that might not be a thing you can do because TFMessage doesn't support it?

Robot_Cpak gravatar image Robot_Cpak  ( 2016-11-02 10:16:07 -0500 )edit

Thanks for the idea! It turned out that I was using the wrong kind of subscribing options - I was using the Transport objects/methods to connect to ROS messages, when the two are separate communications channels.

ElizabethA gravatar image ElizabethA  ( 2016-11-04 08:51:05 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-11-04 08:51:59 -0500

ElizabethA gravatar image

My question was answered on the Gazebo forum.


I ended up needing to use ROS subscribing methods, as used here:

and here:

edit flag offensive delete link more


I also had to update my CMakeLists and add SET(CMAKE_CXX_FLAGS "-std=c++11") to get the 'auto' and 'thread' stuff to compile.

ElizabethA gravatar image ElizabethA  ( 2016-11-04 09:12:46 -0500 )edit

Question Tools

1 follower


Asked: 2016-11-02 09:36:16 -0500

Seen: 684 times

Last updated: Nov 04 '16