having problems with subscribe when using boost::bind

asked 2018-12-21 04:16:05 -0500

zhazha gravatar image

updated 2018-12-21 04:28:15 -0500

here is my code


#include <ros/ros.h>
#include "costmap/costmap.h"
#include <sensor_msgs/LaserScan.h>
int main(int argc, char **argv) {
    ros::init(argc, argv, "costmap");
    ros::NodeHandle n;
    costmap costmap_;
    ros::Subscriber sub = n.subscribe<sensor_msgs::LaserScan::ConstPtr>("scan", 1000, boost::bind(&upDateMap, _1, costmap_));
    ros::spin();
    return 0;}

void upDateMap(const sensor_msgs::LaserScan::ConstPtr &msg, costmap &costmap_){}

and here is my costmap.h:

void upDateMap(const sensor_msgs::LaserScan::ConstPtr &msg, costmap &costmap_);
class costmap {};

costmap is a class defined by me.

When i run catkin_make,In file included from /home/mushen/catkin_ws/src/costmap/src/costmap.cpp:1:0: /home/mushen/catkin_ws/src/costmap/include/costmap/costmap.h:14:61: error: ‘costmap’ has not been declared comes out.

how could i solve this?

edit retag flag offensive close merge delete

Comments

Is the costmap class actually declared in the .cpp file that contains main(..)? If not, it could be that you're simply missing an #include for the header that declares costmap.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-21 04:23:57 -0500 )edit
2

Isn't the issue that you're using costmap (the class) in upDateMap(..)before it's actually declared in costmap.h?

Try swapping the declarations of class costmap and void upDateMap(..) and recompile.

This seems like a straightforward C++ issue to me, not a ROS or boost::bind one.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-21 04:45:03 -0500 )edit