Publishing to a topic via subscriber callback function
Hello, I am wondering if anybody could help me with this problem. I have a listener that just publishes to a topic when another topic is published data, so basically the topic it is listening on gets data published. I have tried putting global variable in the code whose change can map into the main function but ros is not allowing global variables. I also tried to define the nodehandle as global but ros is not allowing this either. (I think before rosinit no ros components will be recognized). My code is in C++. Any help as to what could be done would be really appreciated. I am including a basic skeleton of the code I am trying:
void func_cb(std_msgs type param as defined in ros chatter example)
{
//*need some code here to publish to a topic*
//*problem:nodehandle out of scope,cannot define new nodehandle*
}
int main(... )
{
//ros initilization
//ros node handle initialization
//ros subscription initialization
//callback spinner
return 0;
}