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

Virtual service callbacks

asked 2012-09-21 10:32:57 -0500

Ammar gravatar image

Hello Community, This might seem a strange question. Is it possible to declare a service callback as virtual? Or more importantly can I override the service callback with another function if required? Thanks

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2012-09-22 03:23:08 -0500

Thomas gravatar image

You can use Boost.Bind to binds methods and use them as callbacks.

Callbacks can be changed at runtime (the API usually allows it but in the worst case you can destroy and recreate a publisher/subscriber) so it is not necessary to use complex dispatch methods. Of course, if it benefits code readability, using virtual methods is good too :)

edit flag offensive delete link more

answered 2012-09-21 15:11:30 -0500

ahendrix gravatar image

This should be possible, if you use member function pointers to virtual functions. See:

Caveat: I haven't tried it myself; you probably want to play around with it a bit to make sure it'll work for your use case.

Templates may be a better choice.

edit flag offensive delete link more

Question Tools


Asked: 2012-09-21 10:32:57 -0500

Seen: 423 times

Last updated: Sep 22 '12