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

Why do we need to bind this pointer to a member function in boost::bind?

asked 2020-09-14 20:33:29 -0500

RicoJ gravatar image

Hi,

I noticed in many boost::bind applications, for example here, we need to bind this pointer to a member function.

What does that do?

Thanks, Rico

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-09-15 04:51:00 -0500

Weasfas gravatar image

@RicoJ This question is not really related to ROS and you may want to search or ask in other forums like stackoverflow, but I will answer your question.

boost::bind is a special function used to create a functor for you with the arguments you pass to it. So, it basically creates a new function with the arguments; the problem here is that, if you want to bind a member function you really need to pass, apart from the special placeholders : _1, _2, that store the function arguments, the reference to the object context, that is the special word this.

So the first argument is the reference to the member function, the second, the context of the object itself and then the arguments. If you do not supply the context, the function itself cannot be defined properly within the member scope.

Hope that solve your question.

Regards.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-09-14 20:33:29 -0500

Seen: 855 times

Last updated: Sep 15 '20