Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Bind returns lambda_functor not a function pointer, so how can I cast this functor to function pointer?</p> </blockquote> <p>I don't think you can. However, off the top of my head, I can think of several alternatives: </p> <ul> <li><p>Use <code>boost::function&lt;void()&gt;</code> (or <code>std::function()</code> if your compiler supports TR1 or C++11) instead of <code>void (*)()</code>.<br> It has the ability to bind to just about anything with a somewhat compatible signature. </p></li> <li><p>Put the whole code into a template, make <code>PFUNCPLUGINCMD</code> a template parameter, and let function template argument deduction figure out the exact type. That's a variation on the former, actually, where you would use the result of <code>bind()</code> directly instead of having <code>boost::function</code> abstract away the gory details. </p></li> <li><p>Create a wrapper that calls the functor returned by <code>boost::bind()</code>.<br> A function template might help to let the compiler figure out the exact types and generate a suitable function, although I haven't tried to do that. However, since you cannot use the result of <code>bind()</code> as a template argument, but need to have give the function access to it nevertheless, you will need a global variable for this. (The ability to avoid this is one of the main advantages of function objects, a very versatile of which is <code>std::function</code>.) </p></li> <li><p>Extend your <code>PFUNCPLUGINCMD</code> callback type to support a user-provided parameter. For C callbacks, this usually is a <code>void*</code>. However, if you pass the address of the object returned by <code>bind()</code> to your callback, you would need to convert it into a pointer to the correct type - which, AFAIK, depends on the arguments provided to <code>bind()</code>. In order to avoid that, you'd need to pass something that abstracts away the exact type. Again, <code>std::function</code> comes to the rescue. </p></li> </ul> <p>The first idea would be the best, but it requires you to be able to change <code>PFUNCPLUGINCMD</code>. The last one might be best when <code>PFUNCPLUGINCMD</code> needs to be compatible with C, as it uses the common C callback idiom. </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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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