Ask Your Question

How to initialize a subscriber only when a 'if' condition meets?

asked 2019-07-06 00:54:52 -0600

JeyP4 gravatar image

updated 2019-07-06 05:05:03 -0600

Hello. I want to initialize a subscriber only when

if(i>0){              // 'i' is received as node argument
  ros::Subscriber sub = nh.subscribe("/image_rect_color/compressed", 1, imageCallback);

Problem I am facing is: main thread comes into if-scope but couldn't initialize the subscriber. I guess problem is introduction of new scope.

BTW:This code is in main().

How can this problem be solved?


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-07-06 15:56:40 -0600

JeyP4 gravatar image
ros::Subscriber sub;

if(i>0){              // 'i' is received as node argument
sub = nh.subscribe("/image_rect_color/compressed", 1, imageCallback);

This worked for me.

edit flag offensive delete link more

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


Asked: 2019-07-06 00:54:52 -0600

Seen: 59 times

Last updated: Jul 06 '19