mardi 27 janvier 2015

Function pointer used as reference for callback not being called [on hold]

I have two classes, Banana and Pear, both inheriting from Fruit. These classes wrap libuv. libuv makes heavy use of callbacks and one of those has this signature:


typedef void (*uv_signal_cb)(uv_signal_t* handle, int signum);


Because I want to pass a different callback method depending on the instance of Fruit that I have, I've created a function pointer that gets instantiated by each child of Fruit:


Fruit.h, protected:void (*signal_callback)(uv_signal_t *handle, int signum);


Fruit.cpp: this->signal_callback = &fruit_signal_callback;


Banana.cpp:this->signal_callback = &banana_signal_callback;


The signature for both fruit_signal_callback and banana_signal_callback match what libuv expects.


The problem is that although the code compiles, the methods are never called. I have a number of std::cerr statements in them and they never appear on the console, plus the clean-up code they contain is never executed.


Any ideas?


Aucun commentaire:

Enregistrer un commentaire