Setting up your robot using tf - boost::bind()
Hello all, I am passing just a hard time trying to understand ros, c++ and associated concepts. Probably, here is not the best place to post the question, but I will glad with some help me with my doubts.
Here we go. From the Setting up your robot using tf Navigation Stack tutoriais we have the following snippet code:
ros::Timer timer = n.createTimer(ros::Duration(1.0),
boost::bind(&transformPoint,
boost::ref(listener)));
I am not sure that I really understand what is going here. For me, it seems that in every second the method boost::bind will be called as a callback function. This method, when called, will call the function transformPoint passing to it the argument listener in terms of boos::ref(). In general, I suppose that this is what is happening but I thinking that I am missing something. So, I have some questions.
1_ Why it is used boost::ref to pass the listener variable as argument? Could I pass it directly, i.e. without the method boost::ref?
As a exercise, I tried to reproduce the same behavior in the following code:
#include <iostream>
#include "boost/bind.hpp"
#include "boost/ref.hpp"
void show(char a){
std::cout << a << std::endl;
}
int main() {
char letter = 'a';
boost::bind(&show, boost::ref(letter));
}
But, It did not work as I as expecting. The function show was not called.
2_ It is possible to reproduce the same behavior presented by the snippet code above? If so, how?
I could reproduce a similar behavior with:
int main() {
char letter = 'a';
boost::bind(&show, _1)(boost::ref(letter));
}
But, it is in the same format that it is used in the ros implementation.
Thanks in advance, any help is welcome.
ps. I already look for exemples in internet, but I could not find exactly the answer to my doubts.