Ask Your Question
0

actionlib constructor initialization

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

dj0405 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

Comments

1

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 imageMbuijs ( 2019-10-21 05:47:44 -0600 )edit
1

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 imagegvdhoorn ( 2019-10-21 07:32:10 -0600 )edit

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

Mbuijs gravatar imageMbuijs ( 2019-10-21 15:06:53 -0600 )edit

1 Answer

Sort by » oldest newest most voted
4

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

ahendrix gravatar image

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

The actionlib::SimpleActionServerclass does not have a default constructor: http://docs.ros.org/melodic/api/actio...

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

Comments

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

dj0405 gravatar imagedj0405 ( 2019-10-20 10:03:06 -0600 )edit
1

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.

From https://en.cppreference.com/w/cpp/lan...

ahendrix gravatar imageahendrix ( 2019-10-21 00:45:42 -0600 )edit

I tend to use cppreference.com 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 imageahendrix ( 2019-10-21 00:47:12 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

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

Seen: 23 times

Last updated: Oct 19