2 years ago

#68927

test-img

zhixin

error: cannot bind non-const lvalue reference of type ... to an rvalue of type ... when initializing an SimpleActionClient obj in .h file

I recently developed a ros pkg, I want to initialize an action client object as a member var in head file, so that I can use it in different member functions.

Here is the code in .h file:

    actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction> move_planner_
        = actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction>("move_base", true);

Here is actionlib::SimpleActionClient implementation:

template<class ActionSpec>
class SimpleActionClient
{
    ...
  SimpleActionClient(const std::string & name, bool spin_thread = true)
  : cur_simple_state_(SimpleGoalState::PENDING)
  {
    initSimpleClient(nh_, name, spin_thread);
  }
...
}

But compiler give me error:

 error: cannot bind non-const lvalue reference of type ‘actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction_<std::allocator<void> > >&’ to an rvalue of type ‘actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction_<std::allocator<void> > >’
         = actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction>("move_base", true);
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I don't understand why actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction> move_planner_ turn out to be a rvalue.

c++

ros

0 Answers

Your Answer

Accepted video resources