how does it work when a member variable in an initializer list takes multiple arguments? If my understanding is correct, such a variable takes only one argument...
The actual code where I encountered this problem is shown below, and you can find that member group_trajectory
takes three arguments.
ChompOptimizer::ChompOptimizer(ChompTrajectory* trajectory, const planning_scene::PlanningSceneConstPtr& planning_scene,
const std::string& planning_group, const ChompParameters* parameters,
const moveit::core::RobotState& start_state)
: full_trajectory_(trajectory)
, robot_model_(planning_scene->getRobotModel())
, planning_group_(planning_group)
, parameters_(parameters)
, group_trajectory_(*full_trajectory_, planning_group_, DIFF_RULE_LENGTH)
, planning_scene_(planning_scene)
, state_(start_state)
, start_state_(start_state)
, initialized_(false)
{
If my understanding is correct, such a variable takes only one argument...
That's incorrect. Initializing a data member obeys to the rules the type of the data member yields. If a data member's constructor takes one argument, it must be initialized like that. If it takes three, you must provide three. The example code you show might be misleading because all other constructors require only one argument - but that's a coincidence (or good practice, considering long argument lists a flaw). Example:
struct A {
A(int) {} // takes one argument
A(int, double) {} // overload with two arguments
};
struct B {
B(int, int, int) {} // takes three argument
};
struct Test {
Test() :
a(42), b(42, 43, 44) {}
A a;
B b;
};
In this example, a(42)
could also be a(42, 3.14)
, as such a constructor is available, too. Just pass what's required by the type to instantiate.