Home | Tutorials | Wiki | Issues
Ask Your Question

Subscribe messages: errors at building the "topic tutorial" from the wiki

asked 2012-10-30 14:52:12 -0600

FerdinandT gravatar image

I tried to get run an example of the tutorial section of the wiki: to subscribe and print out messages. I use this code snippet:

#include <stdio.h>
#include <string>    
#include "gazebo.hh"
#include "Transport.hh"
#include "Node.hh"
#include "subscribe.pb.h"
#include "msgs.h"
#include "world_stats.pb.h"
#include "MessageTypes.hh"

using namespace std;
using namespace gazebo;

void printMsg(Const WorldStatisticsPtr &_msg)
  std::cout << _msg->DebugString();

int main()
  gazebo::transport::NodePtr node(new transport::Node());   
  node->Subscribe("~/world_stats", &printMsg, this);
  return 0;

where I removed the last lines of the tutorial. During compiling, I got the following error(s):

   /test2_Gazebo/mainGazebo.cc:15:15: error: variable or field 'printMsg' declared void
   /test2_Gazebo/mainGazebo.cc:15:15: error: 'Const' was not declared in this scope
   /test2_Gazebo/mainGazebo.cc: In function 'int main()':
   /test2_Gazebo/mainGazebo.cc:25:37: error: 'printMsg' was not declared in this scope
   /test2_Gazebo/mainGazebo.cc:25:47: error: invalid use of 'this' in non-member function

After searching for the error in the void function, I guess, that it has something to do with the argument, which could not be proper. Maybe I have to include some more header files? I tried to look around in the source files, but my poor attempts with "world_stats.pb.h", "msgs.h" and "MessageTypes.hh" haven't changed anything. The message system bases on google protobufs, is there a special knowledge about the handling necessary?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-01-11 18:30:57 -0600

scpeters gravatar image

There was a typo in the tutorial; thank you for catching it! There should be no space between Const and WorldStatisticsPtr, so line 15 should actually be:

void printMsg(ConstWorldStatisticsPtr &_msg)

Also, you can't use the 'this' keyword from a main function. I suggest you try integrating this code with one of the example plugins.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2012-10-30 14:52:12 -0600

Seen: 174 times

Last updated: Jan 11 '13