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

Jochen Katz katz at agentpp.com
Mon Aug 7 23:35:06 CEST 2006


Hi,

> Of course you are right with that. But my point was the C function.

ok, I just thought, that some documentation requested this...

> 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.

Well, it was the usual way to do, whenever a lib gets (for the lib
unknown) data from the user and has to give it back later.
It is save, as long as you pass a pointer of type "class XYZ" and cast
the returned pointer back to a "class XYZ" pointer"

Of course, one modern way would be to pass a pointer to a SnmpCallback
object. Until now, nobody asked for such a change.

class SnmpCallback
{
  public:
  virtual void callback(int reason, Snmp *snmp, Pdu &pdu,
                        SnmpTarget &target, void *cd) = 0;
};

Regards,
  Jochen



More information about the AGENTPP mailing list