ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Declare array of custom type

asked 2014-07-16 13:52:19 -0600

Edmodi gravatar image

Hi, I'm triying to declare an array of custom type that I created. This type is formed by 2 int32 variables. I'm triying do that with this command:

main::myType[] myarray;

where main is my package name. When I compiled the program I received an error

Which is the correct way to do this? Thanks in advance

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2014-07-18 01:49:07 -0600

McMurdo gravatar image

The correct format for message-type in a .msg file is

package_name/data_type_name[] variable name

Where data_type_name is a message in the package package_name

eg.

std_msgs/Float64[] values

Note that this is not a regular array in c++.

After generating the msg file, if you look at the .h file for that message, you will find that values is a vector of doubles.

std::vector <double> values;
edit flag offensive delete link more

Comments

Thanks, I will do it.

Edmodi gravatar image Edmodi  ( 2014-07-21 07:03:38 -0600 )edit
0

answered 2014-07-16 16:16:53 -0600

DevonW gravatar image

This is a general programming question; it should be posted on stackoverflow or some other site, but this time I will answer it for you.

int[] array; your_type[] array; namespace::your_type[] array;

Are you trying to make an array inside of a *.msg file?

edit flag offensive delete link more

Comments

Yes I do but this .msg file containt more variables than the array and I do not want use more memory. In concreted, the error is: > expected unqualified-id before ‘[’ token Thanks

Edmodi gravatar image Edmodi  ( 2014-07-17 03:10:37 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-07-16 13:52:19 -0600

Seen: 1,967 times

Last updated: Jul 18 '14