[AGENT++] C++ function within snmp++ callback

Manuel Werlberger m.werlberger at avibit.com
Mon Aug 7 08:43:08 CEST 2006


Jochen Katz wrote:

>who demands the "extern "C""? It just has to be a C function, not a
>function within a class.
>  
>
Of course you are right with that. But my point was the C function. I 
don't wan't to have global variables in my program just for passing on 
values i get from the callback. But you've shown a method down below 
here -->

>In the QtExample I used the data pointer param and the callback function
>just casts it to a class and calls the member function.
>
>/// C Callback function for snmp++
>void callback(int reason, Snmp *snmp, Pdu &pdu, SnmpTarget &target,
>              void *cd)
>{
>  if (cd)
>  {
>    // just call the real callback member function...
>    ((MainWindow*)cd)->async_callback(reason, snmp, pdu, target);
>  }
>}
>  
>

I didn't thought about casting the callback as a class. Is this save and 
the usual way to do? I'm not a newbie to c++ but to C callback functions 
within c++ i am.

As i posted before i just implemented a signal forwarding class that is 
instantiated as a singelton. In my opinion this is a nice solution to my 
problem as my program builds on the Qt lib so i have signals anyway.

Best regards,
 Manuel



More information about the AGENTPP mailing list