0
$\begingroup$

Rosanswers logo

Hellow,

I have a template class Main. I'm trying to use one of the function of this class as a callBack for a subscriber but I can't compile my code.

If I put a value in the template :

/home/ros/catkin_ws/src/Tobot/stalker/src/Stalker.cpp:27: undefined reference to `Main<pcl::PointXYZRGBA>::doWork(boost::shared_ptr<sensor_msgs::PointCloud2_<std::allocator<void> > const> const&)'

If I don't :

/home/ros/catkin_ws/src/Tobot/stalker/src/Stalker.cpp:27:86: erreur: ‘template<class T> class Main’ used without template parameters
make[2]: *** [Tobot/stalker/CMakeFiles/stalker_node.dir/src/Stalker.cpp.o] Erreur 1

The code for those errors would be respectively :

pointcloud_sub = my_node.subscribe<sensor_msgs::PointCloud2> ("cloud_filtered", 1, &Main<pcl::PointXYZRGBA>::doWork, &main);

pointcloud_sub = my_node.subscribe<sensor_msgs::PointCloud2> ("cloud_filtered", 1, &Main::doWork, &main);

Any help to get this working would be appreciated.


Originally posted by Maya on ROS Answers with karma: 1172 on 2014-04-14

Post score: 1

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

The first call, with template parameters, is correct. The trouble is that the compiler isn't actually emitting the code for that callback function for some reason.

Probably the easiest (and hackiest) thing to do is to add a call to main.doWork() somewhere else in your program, just to convince the compiler to emit the code for it. Ideally, you could put this call on a code path that is unreachable, or call it with an empty argument so that it does nothing.


Originally posted by ahendrix with karma: 47576 on 2014-04-14

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

Silly me, I found the reason.

I put my template function in a cpp while they need to be inline in header file. That's it, that's all.


Originally posted by Maya with karma: 1172 on 2014-04-16

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.