Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to cast to it boost::bind(&myClass::fun, this, _1, _2, _3) to typedef void (*fun)(arg1, arg2, arg3)?
    text
    copied!<p>In lib Bullet there is defined a type:</p> <pre><code>typedef void (*btNearCallback)(btBroadphasePair&amp; collisionPair, btCollisionDispatcher&amp; dispatcher, const btDispatcherInfo&amp; dispatchInfo); </code></pre> <p>in there docs there is presented a <a href="http://www.bulletphysics.com/ftp/pub/test/physics/Bullet_User_Manual.pdf" rel="nofollow noreferrer">sample of usage (page 23)</a>:</p> <pre><code>void MyNearCallback(btBroadphasePair&amp; collisionPair, btCollisionDispatcher&amp; dispatcher, const btDispatcherInfo&amp; dispatchInfo) { // Do your collision logic here // Only dispatch the Bullet collision information if you want the physics to continue dispatcher.defaultNearCallback(collisionPair, dispatcher, dispatchInfo); } </code></pre> <p>I copied this sample code into my class defention so my class got this function and I shall be capable to do such casts like:</p> <pre><code> dispatcher-&gt;setNearCallback(boost::bind(&amp;BulletAPIWrapper::MyNearCallback, this, _1, _2, _3)); </code></pre> <p>instead of C like <code>dispatcher-&gt;setNearCallback(MyNearCallback);</code> from Bullet tutorial.</p> <p>Yet my VS2010 sp1 gives me an error:</p> <pre><code>Error 44 error C2664: 'btCollisionDispatcher::setNearCallback' : cannot convert parameter 1 from 'boost::_bi::bind_t&lt;R,F,L&gt;' to 'btNearCallback' </code></pre> <p>So I wonder how to cast boost::bind to such typedef?</p> <p>Is it possible having having static class function (or at least global function like):</p> <pre><code>void MyNearCallback(btBroadphasePair&amp; collisionPair, btCollisionDispatcher&amp; dispatcher, const btDispatcherInfo&amp; dispatchInfo, BulletAPI* api) { } </code></pre> <p>call <code>dispatcher-&gt;setNearCallback( boost::bind(MyNearCallback, _1, _2, _3, this));</code></p> <p>because it results in nearly same error for me:</p> <pre><code>Error 44 error C2664: 'btCollisionDispatcher::setNearCallback' : cannot convert parameter 1 from 'boost::_bi::bind_t&lt;R,F,L&gt;' to 'btNearCallback' </code></pre> <p>I also tried <a href="https://stackoverflow.com/a/13238113/1973207">as described here</a>:</p> <pre><code>template&lt;unsigned ID,typename Functor&gt; boost::optional&lt;Functor&gt; &amp;get_local() { static boost::optional&lt;Functor&gt; local; return local; } template&lt;unsigned ID,typename Functor&gt; typename Functor::result_type wrapper(btBroadphasePair&amp; collisionPair, btCollisionDispatcher&amp; dispatcher, const btDispatcherInfo&amp; dispatchInfo) { return get_local&lt;ID,Functor&gt;().get()(collisionPair, dispatcher, dispatchInfo); } template&lt;typename ReturnType&gt; struct Func { typedef ReturnType (*type)(btBroadphasePair&amp; collisionPair, btCollisionDispatcher&amp; dispatcher, const btDispatcherInfo&amp; dispatchInfo); }; template&lt;unsigned ID,typename Functor&gt; typename Func&lt;typename Functor::result_type&gt;::type get_wrapper(Functor f) { (get_local&lt;ID,Functor&gt;()) = f; return wrapper&lt;ID,Functor&gt;; } struct NearCallbackWrapper { class BulletAPI; void MyNearCallback(btBroadphasePair&amp; collisionPair, btCollisionDispatcher&amp; dispatcher, const btDispatcherInfo&amp; dispatchInfo) { std::cout &lt;&lt; "called" &lt;&lt; std::endl; } }; //.... dispatcher-&gt;setNearCallback( get_wrapper&lt;0&gt;( boost::bind(&amp;NearCallbackWrapper::MyNearCallback,this) ) ); </code></pre> <p>yet I got such error out from it:</p> <pre><code>error C2664: 'btCollisionDispatcher::setNearCallback' : cannot convert parameter 1 from 'void (__cdecl *)(btBroadphasePair &amp;,btCollisionDispatcher &amp;,const btDispatcherInfo &amp;)' to 'btNearCallback' </code></pre>
 

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