How to initialize a subscriber only when a 'if' condition meets?
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?
Thanks