How to add/design callback function
问题 How do I setup/register a callback function, in C++, to call a function when there is data to be read from a queue? Edit 1: Using Neil's answer for a complete answer (in header file): #include <vector.h> class QueueListener { public: virtual void DataReady(class MyQueue *q) = 0; virtual ~QueueListener() {} }; class MyQueue { public: void Add (int x) { theQueue.push_back(x); for (int i = 0; i < theCallBacks.size(); i++) { theCallBacks[i]->DataReady(this); } } void Register (QueueListener *ql)