1

I'm using Kinetic.

I have a custom message path.msg

string path_name
segment[] segments

I'm trying to send a ROS goal with that message type.

I initialize an array in my code

cuarl_rover_planner::segment segments[path->getSegments().size()];
//do stuff that populates the array
cuarl_rover_planner::path action_path;
action_path.segments = segments; // Error here

I get this error

error: no match for ‘operator=’ (operand types are ‘cuarl_rover_planner::path_<std::allocator<void> >::_segments_type {aka std::vector<cuarl_rover_planner::segment_<std::allocator<void> >, std::allocator<cuarl_rover_planner::segment_<std::allocator<void> > > >}’ and ‘cuarl_rover_planner::segment [(<anonymous> + 1)] {aka cuarl_rover_planner::segment_<std::allocator<void> > [(<anonymous> + 1)]}’)
         action_path.segments = segments;

I'm assuming that the action_path.segments take a different data type, but I don't understand what that datatype is, from that error message.

Cedric Martens
  • 1,139
  • 10
  • 23

1 Answers1

1

action_path.segments is a std::vector<segment>, but your segments variable is just a single segment, not a vector of segments. If you want to add only one segment, you can use action_path.push_back(segment). Otherwise, you can declare segments as

std::vector<cuarl_rover_planner::segment> segments(path->getSegments().size());

If you wanted to use a raw pointer array for some reason (like you might be here), you have to explicitly set that up as std::vector first, i.e.

action_path.segments = std::vector<cuarl_rover_planner::segment>(segments, segments+path->getSegments().size());

See How to initialize std::vector from C-style array? for more about setting a vector from a raw C-array.

chessbot
  • 436
  • 2
  • 11