Ask Your Question

How does one assign values to messages with arrays in C++

asked 2020-10-19 18:56:43 -0500

cwillia109 gravatar image

This is probably more C++ focused, but here is my issue:

int8_t vi[height * width];
// vi has had work done on it between here
nav_msgs::OccupancyGrid debMap; = vi; // error here

The resulting error is:

no operator "=" matches these operands -- operand types are: std::vector<int8_t, std::allocator<int8_t>> = int8_t [height * width]

Now in python something like this would be an issue. In the past I have been using memcpy to get around this, but I am less certain that that is the approach to take for this.

How can I add array data to a message with an array.

edit retag flag offensive close merge delete



I believe, one brute force method is,

for (int i = 0; i<height*width; i++) {[i]);

I'm dunno if there is a way to directly assign it to data. May be treated as std::vector and use one of the suggested methods here.

praskot gravatar image praskot  ( 2020-10-19 23:15:29 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2020-10-20 00:09:56 -0500

KenYN gravatar image

Here's one way to do it:, vi + height * width);

Cribbed from this answer on StackOverflow.

edit flag offensive delete link more


This worked like a charm. Thank you!

cwillia109 gravatar image cwillia109  ( 2020-10-22 12:54:49 -0500 )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



Asked: 2020-10-19 18:56:43 -0500

Seen: 350 times

Last updated: Oct 20 '20