Wednesday 15 September 2010

c++ - Type for a function pointer that will be used in boost::bind -


I am doing messaging library around the websocket ++ library. This library allows me to set up my own tasks to manage messages. As I am not applying the final which will use my code, I also need to allow my users to set their desired actions for this handler.

How it works nowhere is a socket (m_client) class in which its set_handler function is used which is similar to the following snippet.

  m_client.set_message_handler (dam (and myFunction, & amp; m_client, _1, _2));   

What I would like to do is provide a function that will take the form of the parameter and my function so that the user simply calls:

  my_class.set_msg_handler ( & Amp; myfunction);   

And then this declaration will be:

  zero set_msg_handler ( myfunction) {m_client.set_message_handler (dam (myfunction, & amp; ; M_client, _1, _2)); }   

But I could not clear it which is the right type for my function, so that it can be compiled. Or if it is also a good way to archive it. I went through the boost code to see if I could get some signals ... but as it ends up working with templates, it's something I do not manage yet.

I know that this user binds itself and passes his output, but m_client is not available directly and I want to keep it for incapusual proposals in such a way. And I think that is no longer strictly necessary, maybe I will need it anyway for some days. So in the proposal to learn I decided to ask it in any way.

I am quite new to using this level on C ++ and the whole pointers and handlers and templates solve a bit for my real understanding. I have read about the use of bind but in all the examples, the function is declared and then the direct binding is used.

Along with this, a similar question was searched, but if it exists it could not be found. And I will not leave that my view is not best or completely wrong, so all the advice and recommendations will be welcome.

The promotion template is probably using

  Lt; Typename T & gt; Zero set_msg_handler (t myfunction) {m_client.set_message_handler (bind (myFunction, & amp; m_client, _1, _2)); }   

But if you want to force the user to give some kind of function, then you can check the template specializations.

But the dam will accept almost any type of sign

No comments:

Post a Comment