<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[boost::bind einer boost::function]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich würde gerne eine kleine Klasse schreiben, die die maximale Anzahl an parallel auszuführenden threads beschränkt (boost-threadpool funktioniert nicht unter VS2010). Jetzt treten bei mir bei der Verwendung von boost::bind und boost:function Compiler-Fehler auf, für die ich keine Erklärung finde. Folgender Code fasst mein Problem zusammen:</p>
<pre><code class="language-cpp">#include &lt;boost/thread.hpp&gt;
#include &lt;boost/bind.hpp&gt;

template&lt;typename F&gt;
void fu_caller (F threadfun)
{
	//check if mutex is lockable....
	//...
	threadfun();
};

template&lt;typename F&gt;
void thread_starter ( F fun)
{
	//funktioniert
	boost::function&lt;void (F)&gt; f = &amp;fu_caller&lt;F&gt;;	

	//direkter aufruf ohne thread funktioniert
	f(fun);

	//bind der boost::function  
	boost::function&lt;void ( void)&gt; f3;

	//funktioniert nicht,  f3 falsch?
	//f3 = boost::bind&lt;void&gt;(&amp;fu_caller&lt;F&gt;,fun);

	//funktioniert
	boost::bind(&amp;fu_caller&lt;F&gt;, fun);

	//funktioniert nicht
	boost::thread t(boost::bind(&amp;fu_caller&lt;F&gt;, fun));
};

int add(int a, int b)
{
	return a+b;
}

int main()
{	
	int a = 2;
	int b = 5;
	thread_starter(boost::bind(&amp;add,a,b));

return;
}
</code></pre>
<p>Fehlermeldung:</p>
<blockquote>
<p>error C2664: 'void (F)': Konvertierung des Parameters 1 von 'int' in 'boost::_bi::bind_t&lt;R,F,L&gt;' nicht möglich d:\libraries\boost_1_46\boost\bind\bind.hpp 253</p>
</blockquote>
<p>Ich nutze den vc90-compiler mit VS2010 und boost-1.46.<br />
Ich hoffe, dass mir jemand weiterhelfen kann <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/295217/boost-bind-einer-boost-function</link><generator>RSS for Node</generator><lastBuildDate>Sat, 15 Aug 2026 08:31:16 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/295217.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 09 Nov 2011 13:02:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to boost::bind einer boost::function on Wed, 09 Nov 2011 13:02:04 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich würde gerne eine kleine Klasse schreiben, die die maximale Anzahl an parallel auszuführenden threads beschränkt (boost-threadpool funktioniert nicht unter VS2010). Jetzt treten bei mir bei der Verwendung von boost::bind und boost:function Compiler-Fehler auf, für die ich keine Erklärung finde. Folgender Code fasst mein Problem zusammen:</p>
<pre><code class="language-cpp">#include &lt;boost/thread.hpp&gt;
#include &lt;boost/bind.hpp&gt;

template&lt;typename F&gt;
void fu_caller (F threadfun)
{
	//check if mutex is lockable....
	//...
	threadfun();
};

template&lt;typename F&gt;
void thread_starter ( F fun)
{
	//funktioniert
	boost::function&lt;void (F)&gt; f = &amp;fu_caller&lt;F&gt;;	

	//direkter aufruf ohne thread funktioniert
	f(fun);

	//bind der boost::function  
	boost::function&lt;void ( void)&gt; f3;

	//funktioniert nicht,  f3 falsch?
	//f3 = boost::bind&lt;void&gt;(&amp;fu_caller&lt;F&gt;,fun);

	//funktioniert
	boost::bind(&amp;fu_caller&lt;F&gt;, fun);

	//funktioniert nicht
	boost::thread t(boost::bind(&amp;fu_caller&lt;F&gt;, fun));
};

int add(int a, int b)
{
	return a+b;
}

int main()
{	
	int a = 2;
	int b = 5;
	thread_starter(boost::bind(&amp;add,a,b));

return;
}
</code></pre>
<p>Fehlermeldung:</p>
<blockquote>
<p>error C2664: 'void (F)': Konvertierung des Parameters 1 von 'int' in 'boost::_bi::bind_t&lt;R,F,L&gt;' nicht möglich d:\libraries\boost_1_46\boost\bind\bind.hpp 253</p>
</blockquote>
<p>Ich nutze den vc90-compiler mit VS2010 und boost-1.46.<br />
Ich hoffe, dass mir jemand weiterhelfen kann <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2142515</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2142515</guid><dc:creator><![CDATA[elsucht]]></dc:creator><pubDate>Wed, 09 Nov 2011 13:02:04 GMT</pubDate></item><item><title><![CDATA[Reply to boost::bind einer boost::function on Wed, 16 Nov 2011 00:35:07 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;boost/bind/protect.hpp&gt;
// ...
thread_starter(boost::protect(boost::bind(&amp;add,a,b)));
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2145036</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2145036</guid><dc:creator><![CDATA[Shlo]]></dc:creator><pubDate>Wed, 16 Nov 2011 00:35:07 GMT</pubDate></item><item><title><![CDATA[Reply to boost::bind einer boost::function on Fri, 18 Nov 2011 15:16:43 GMT]]></title><description><![CDATA[<p>Dankeschön, so hat es übrigens auch geklappt:</p>
<pre><code>thread_starter&lt;boost::function&lt;void(void)&gt;&gt;(boost::bind(&amp;add,a,b)));
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2146039</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2146039</guid><dc:creator><![CDATA[elsucht]]></dc:creator><pubDate>Fri, 18 Nov 2011 15:16:43 GMT</pubDate></item></channel></rss>