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

actionlib constructor initialization

asked 2019-10-19 20:16:07 -0500

emacsd gravatar image

I'd appreciate it if someone can explain the reason why the actionlib simpleServer constructor needs to be initialized as a constructor initializer list? If the initialization's removed the compilation fails.

reference to actionlib tutorials

I know this is more as a C++ question rather than ROS related question!

Thank you.

edit retag flag offensive close merge delete



Aside of ahendrix correct answer below, a suggestion:

If you want to initiate the action server at another moment, you can consider wrapping the actionlib::SimpleActionServer in a std::shared_ptr. I would not suggest it as the default approach, but it can be useful in cases where the action server is not supposed to be active directly at the time of calling the constructor of your class.

Mbuijs gravatar image Mbuijs  ( 2019-10-21 05:47:44 -0500 )edit

If with

If you want to initiate the action server at another moment

you mean it may be desirable to not have the ActionServer instantiated then delaying construction by using a (smart) pointer is indeed an option.

If you were instead thinking of "initiate" as: placing the server in the active state, then perhaps setting auto_start to false (ctor docs) would be a better approach.

gvdhoorn gravatar image gvdhoorn  ( 2019-10-21 07:32:10 -0500 )edit

Good point, I was not thinking of the auto_start option, which is indeed a better approach.

Mbuijs gravatar image Mbuijs  ( 2019-10-21 15:06:53 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-10-19 22:38:41 -0500

ahendrix gravatar image

You are correct; this is a C++ question.

The actionlib::SimpleActionServerclass does not have a default constructor:

Therefore, you must provide constructor arguments when the SimpleActionServer object is constructed. If this object is a member of another class, then the C++ standard states that the constructor arguments must be passed in the initializer list.

edit flag offensive delete link more


Thank you @ahendrix. Do you have any reference/article explains this topic more in depth?

emacsd gravatar image emacsd  ( 2019-10-20 10:03:06 -0500 )edit

Before the compound statement that forms the function body of the constructor begins executing, initialization of all direct bases, virtual bases, and non-static data members is finished. Member initializer list is the place where non-default initialization of these objects can be specified.


ahendrix gravatar image ahendrix  ( 2019-10-21 00:45:42 -0500 )edit

I tend to use for C++ reference material, but you will probably find that a textbook aimed at teaching C++ explains the material in a more approachable way.

ahendrix gravatar image ahendrix  ( 2019-10-21 00:47:12 -0500 )edit

Question Tools



Asked: 2019-10-19 20:16:07 -0500

Seen: 476 times

Last updated: Oct 19 '19