Ask Your Question
0

error: no match for 'operator='

asked 2017-07-18 04:54:31 -0500

Kenn gravatar image

Hey,

I get this error when building the package:

/home/ken/cws/src/mathematics/src/evenNumberGenerator.cpp:24: error: no match for 'operator=' (operand types are 'mathematics::TwoData_<std::allocator<void> >::_data2_type {aka std_msgs::Int8_<std::allocator<void> >}' and 'int')
             number.data2 = i*2;
                          ^

Basically, I am working on this issue, finally I think I figured it out the correct way of using custom messages in my package but I guess I made some mistake in my code.

msg file:

ken@ken-Satellite-L500D:~$ cat cws/src/mathematics/msg/TwoData.msg
std_msgs/Int8 data1
std_msgs/Int8 data2

Does anyone have an idea?

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-07-18 05:07:56 -0500

Chaos gravatar image

Did you try with

number.data2.data = i*2;

?

edit flag offensive delete link more

Comments

Thank you, that was it! But why? I don't remember such a syntax was mentioned anywhere in tutorials.

Kenn gravatar imageKenn ( 2017-07-18 05:21:42 -0500 )edit

I think it is because std_msgs/Int8 is a structured data (a class I think). If you try with just Int8 you can get direct access to the data. Check this.

Chaos gravatar imageChaos ( 2017-07-18 05:23:55 -0500 )edit

I just attempted compiling the package with Int8 data1 (data2), without std_msgs/ in my msg folder, it gives some dependency errors. I believe in some of the answers here I saw the correct use of message declaration was like this "package/type name".

Kenn gravatar imageKenn ( 2017-07-18 05:30:22 -0500 )edit

Note: the primitive is int8, the message name is Int8 (with a capital i). The first is a built-in, the second is a message in std_msgs. The latter requires you add the std_msgs/ prefix.

gvdhoorn gravatar imagegvdhoorn ( 2017-07-18 07:26:48 -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

1 follower

Stats

Asked: 2017-07-18 04:54:31 -0500

Seen: 1,042 times

Last updated: Jul 18 '17