Note that there are some explanatory texts on larger screens.

plurals
  1. POcalling function pointer of a member function from a function pointer vector
    primarykey
    data
    text
    <p>i think this is mostly a syntax error ( though not captured during compilation, only at runtime does the error happen)</p> <p>i am trying to develop an event driven architecture , where i keep a vector of eventReceiver and try to call them from the vector.</p> <p><strong>CommonIO.h</strong></p> <pre><code> class CommonIO { public: typedef void (*incomingMsgReceiver)(char*); void registerForIncomingMsg(incomingMsgReceiver); void incomingMsgReceived(char*); } </code></pre> <p><strong>CommonIO.cpp</strong></p> <pre><code> std::vector&lt;void (*)(char*)&gt; listeners; void CommonIO::registerForIncomingMsg(incomingMsgReceiver receiverFunction) { listeners.push_back(receiverFunction); } void CommonIO::incomingMsgReceived(char* buf) { for (unsigned int j = 0; j &lt; listeners.size(); j++) { listeners[i](buf); //error, segmentation fault..how do i call it? } } </code></pre> <p><strong>Main.h</strong></p> <pre><code>class Main { public: static void msgReceived(char*); void mainLoop(); } </code></pre> <p><strong>Main.cpp</strong></p> <pre><code>void Main::msgReceived(char* msg) { printf("\n\n ---------&gt;&gt;&gt;&gt;&gt; %s \n\n" , msg); } void Main::mainLoop() { CommonIO::incomingMsgReceiver receiver = &amp;Main::msgReceived; CommonIO::getInstance()-&gt;registerForIncomingMsg( receiver ); } </code></pre> <p>incomingMsgReceived function is called by an asynchronous process</p> <p>the program compiles fine..however breaks down at : listenersi; line. what is the proper syntax for this ? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload