<?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[Unklare Compiler Fehlermeldung]]></title><description><![CDATA[<p>Ich habe boost mit threads installiert. Ich muss Multithreading unter C++ lernen. Dazu habe ich folgendes Programm geschrieben:</p>
<pre><code class="language-cpp">#ifndef TESTMULTITHREADING_H
#define TESTMULTITHREADING_H

#include &lt;boost/thread.hpp&gt;

class TestMultiThreading {

	public:
	TestMultiThreading();
	void writeSomething( int num );

};

#endif
</code></pre>
<p>und</p>
<pre><code class="language-cpp">#include &quot;TestMultiThreading.h&quot;

#include &lt;stdio.h&gt;

TestMultiThreading::TestMultiThreading() {
	for( int i = 1; i &lt;= 3; ++i )
		boost::thread myThread( writeSomething, i );
}

void TestMultiThreading::writeSomething( int num ) {
	for( int i = 0; i &lt; 10; ++i )
		printf(&quot;Ich bin Thread %d\n&quot;, num);
}

int main( int argc, const char* argv[] ) {
	printf( &quot;MultiThreading?\n&quot; );
	TestMultiThreading mt;
}
</code></pre>
<p>Nun erhalte ich beim Kompilieren folgenden Fehler:</p>
<pre><code>[anthovak@findthee test]$ make
g++ -m64 -g -Wall -Werror -Wcomment -I./boost_1_43_0/include -o TestMultiThreading.o -c TestMultiThreading.cpp
TestMultiThreading.cpp: In constructor ‘TestMultiThreading::TestMultiThreading()’:
TestMultiThreading.cpp:7: error: no matching function for call to ‘boost::thread::thread(&lt;unresolved overloaded function type&gt;, int&amp;)’
./boost_1_43_0/include/boost/thread/detail/thread.hpp:248: note: candidates are: boost::thread::thread(F, A1) [with F = void (TestMultiThreading::*)(int), A1 = int]
./boost_1_43_0/include/boost/thread/detail/thread.hpp:214: note:                 boost::thread::thread(boost::detail::thread_move_t&lt;boost::thread&gt;)
./boost_1_43_0/include/boost/thread/detail/thread.hpp:200: note:                 boost::thread::thread(F, typename boost::disable_if&lt;boost::is_convertible&lt;T&amp;, boost::detail::thread_move_t&lt;T&gt; &gt;, boost::thread::dummy*&gt;::type) [with F = void (TestMultiThreading::*)(int)]
./boost_1_43_0/include/boost/thread/detail/thread.hpp:153: note:                 boost::thread::thread()
./boost_1_43_0/include/boost/thread/detail/thread.hpp:121: note:                 boost::thread::thread(boost::detail::thread_data_ptr)
./boost_1_43_0/include/boost/thread/detail/thread.hpp:111: note:                 boost::thread::thread(boost::thread&amp;)
make: *** [TestMultiThreading.o] Error 1
</code></pre>
<p>Nun verstehe ich die Fehlermeldung so, dass &quot;boost::thread::thread(&lt;unresolved overloaded function type&gt;, int&amp;)&quot; nicht mit zB &quot;boost::thread::thread(F, A1) [with F = void (TestMultiThreading::*)(int), A1 = int]&quot; übereinstimmt.</p>
<p>Wie sage ich denn boost::thread, dass das erste Argument eine Methode vom Typ &quot;void (TestMultiThreading::*)(int)&quot; ist und &quot;A1 = int&quot; ?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/270953/unklare-compiler-fehlermeldung</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 18:02:04 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/270953.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 20 Jul 2010 21:43:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Unklare Compiler Fehlermeldung on Tue, 20 Jul 2010 21:43:26 GMT]]></title><description><![CDATA[<p>Ich habe boost mit threads installiert. Ich muss Multithreading unter C++ lernen. Dazu habe ich folgendes Programm geschrieben:</p>
<pre><code class="language-cpp">#ifndef TESTMULTITHREADING_H
#define TESTMULTITHREADING_H

#include &lt;boost/thread.hpp&gt;

class TestMultiThreading {

	public:
	TestMultiThreading();
	void writeSomething( int num );

};

#endif
</code></pre>
<p>und</p>
<pre><code class="language-cpp">#include &quot;TestMultiThreading.h&quot;

#include &lt;stdio.h&gt;

TestMultiThreading::TestMultiThreading() {
	for( int i = 1; i &lt;= 3; ++i )
		boost::thread myThread( writeSomething, i );
}

void TestMultiThreading::writeSomething( int num ) {
	for( int i = 0; i &lt; 10; ++i )
		printf(&quot;Ich bin Thread %d\n&quot;, num);
}

int main( int argc, const char* argv[] ) {
	printf( &quot;MultiThreading?\n&quot; );
	TestMultiThreading mt;
}
</code></pre>
<p>Nun erhalte ich beim Kompilieren folgenden Fehler:</p>
<pre><code>[anthovak@findthee test]$ make
g++ -m64 -g -Wall -Werror -Wcomment -I./boost_1_43_0/include -o TestMultiThreading.o -c TestMultiThreading.cpp
TestMultiThreading.cpp: In constructor ‘TestMultiThreading::TestMultiThreading()’:
TestMultiThreading.cpp:7: error: no matching function for call to ‘boost::thread::thread(&lt;unresolved overloaded function type&gt;, int&amp;)’
./boost_1_43_0/include/boost/thread/detail/thread.hpp:248: note: candidates are: boost::thread::thread(F, A1) [with F = void (TestMultiThreading::*)(int), A1 = int]
./boost_1_43_0/include/boost/thread/detail/thread.hpp:214: note:                 boost::thread::thread(boost::detail::thread_move_t&lt;boost::thread&gt;)
./boost_1_43_0/include/boost/thread/detail/thread.hpp:200: note:                 boost::thread::thread(F, typename boost::disable_if&lt;boost::is_convertible&lt;T&amp;, boost::detail::thread_move_t&lt;T&gt; &gt;, boost::thread::dummy*&gt;::type) [with F = void (TestMultiThreading::*)(int)]
./boost_1_43_0/include/boost/thread/detail/thread.hpp:153: note:                 boost::thread::thread()
./boost_1_43_0/include/boost/thread/detail/thread.hpp:121: note:                 boost::thread::thread(boost::detail::thread_data_ptr)
./boost_1_43_0/include/boost/thread/detail/thread.hpp:111: note:                 boost::thread::thread(boost::thread&amp;)
make: *** [TestMultiThreading.o] Error 1
</code></pre>
<p>Nun verstehe ich die Fehlermeldung so, dass &quot;boost::thread::thread(&lt;unresolved overloaded function type&gt;, int&amp;)&quot; nicht mit zB &quot;boost::thread::thread(F, A1) [with F = void (TestMultiThreading::*)(int), A1 = int]&quot; übereinstimmt.</p>
<p>Wie sage ich denn boost::thread, dass das erste Argument eine Methode vom Typ &quot;void (TestMultiThreading::*)(int)&quot; ist und &quot;A1 = int&quot; ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1929366</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1929366</guid><dc:creator><![CDATA[HändyÄndy]]></dc:creator><pubDate>Tue, 20 Jul 2010 21:43:26 GMT</pubDate></item><item><title><![CDATA[Reply to Unklare Compiler Fehlermeldung on Tue, 20 Jul 2010 23:37:53 GMT]]></title><description><![CDATA[<p><code>boost.bind</code> dürfte bei der Methode helfen.</p>
<pre><code class="language-cpp">for( int i = 1; i &lt;= 3; ++i )
        boost::thread myThread( writeSomething, i );
</code></pre>
<p>Das ist wahrscheinlich so nicht möglich, weil die <code>thread</code> -Objekte zerstört werden, bevor der Thread jeweils zuende ist.<br />
Mach das ungefähr so:</p>
<pre><code class="language-cpp">boost::array&lt;std::auto_ptr&lt;boost::thread&gt;, 3&gt; threads;
for (size_t i = 0; i &lt; threads.size(); ++i)
{
	threads[i].reset(new boost::thread(boost::bind(&amp;TestMultiThreading::writeSomething, this, i)));
}
for (size_t i = 0; i &lt; threads.size(); ++i)
{
	threads[i]-&gt;join();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1929383</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1929383</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Tue, 20 Jul 2010 23:37:53 GMT</pubDate></item><item><title><![CDATA[Reply to Unklare Compiler Fehlermeldung on Wed, 21 Jul 2010 09:18:41 GMT]]></title><description><![CDATA[<p>Okay, danke für die Antwort.</p>
<p>Gibt es eigentlich ein gute Dokumentation zu boost. Die offizielle Doku auf deren Homepage ist vollkommen miserabel. Ich versteh da jedenfalls garnix.</p>
<p>Ich habe jetzt schon wieder ein Problem, das ich mir nicht mit Hilfe der boost Doku erklären oder lösen kann. Nun habe ich folgendes, wie ich denke sehr einfaches Problem, das ich nicht gelöst bekomme.</p>
<pre><code class="language-cpp">TestMultiThreading::TestMultiThreading() {

	boost::thread thread1( boost::bind( &amp;TestMultiThreading::provide_data, this ) );
	boost::thread thread2( boost::bind( &amp;TestMultiThreading::process_data, this ) );

	thread1.join();
	thread2.join();
}

void TestMultiThreading::provide_data( boost::thread thread ) {
	for( int i = 0; i &lt; 10; ++i ) {
		boost::mutex::scoped_lock lock(mtx);
		var = i; 
		boost::thread::sleep(1); &lt;-- Zeile 38
	}
}

void TestMultiThreading::process_data() {
	int local_var = 0;
	while( local_var != 9 ) {
		boost::mutex::scoped_lock lock(mtx);
		local_var = var;
		cout &lt;&lt; local_var &lt;&lt; endl;
	}
}
</code></pre>
<p>Compiler meckert und will nicht.</p>
<blockquote>
<p>[anthovak@findthee test]$ make<br />
g++ -m64 -g -Wall -Werror -Wcomment -I./boost_1_43_0/include -o TestMultiThreading.o -c TestMultiThreading.cpp<br />
TestMultiThreading.cpp: In member function ‘void TestMultiThreading::provide_data()’:<br />
TestMultiThreading.cpp:38: error: invalid conversion from ‘int’ to ‘boost::date_time::special_values’<br />
TestMultiThreading.cpp:38: error: initializing argument 1 of ‘boost::posix_time::ptime::ptime(boost::date_time::special_values)’<br />
make: *** [TestMultiThreading.o] Error 1</p>
</blockquote>
<p>Wie kann ich denn dem Programm sagen, dass der Thread der aktuell die Mehtode provide_data ausführt, mal ne Sekunde warten soll bis er weitermacht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1929465</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1929465</guid><dc:creator><![CDATA[HändyÄndy]]></dc:creator><pubDate>Wed, 21 Jul 2010 09:18:41 GMT</pubDate></item><item><title><![CDATA[Reply to Unklare Compiler Fehlermeldung on Wed, 21 Jul 2010 09:54:29 GMT]]></title><description><![CDATA[<p>Okay, ich habs dann sogar doch noch hinbekommen. Hier ist der Code. Thread1 &quot;erzeugt&quot; Zahlen, die dann von Thread2 ausgegeben werden sollen und zwar so, dass bei der Variablenübergabe nur exklusiv gelesen/geschrieben werden darf.</p>
<pre><code class="language-cpp">#ifndef TESTMULTITHREADING_H
#define TESTMULTITHREADING_H

#include &lt;boost/thread.hpp&gt;
#include &lt;boost/thread/mutex.hpp&gt;

class TestMultiThreading {

	public:
	boost::mutex mtx;
	int var;
	TestMultiThreading();
	void provide_data();
	void process_data();

};

#endif
</code></pre>
<pre><code class="language-cpp">#include &quot;TestMultiThreading.h&quot;

#include &lt;stdio.h&gt;
#include &lt;iostream&gt;
#include &lt;boost/array.hpp&gt;
#include &lt;boost/date_time/posix_time/posix_time.hpp&gt;

using std::cout;
using std::endl;

TestMultiThreading::TestMultiThreading() {

	boost::thread thread1( boost::bind( &amp;TestMultiThreading::provide_data, this ) );
	boost::thread thread2( boost::bind( &amp;TestMultiThreading::process_data, this ) );

	thread1.join();
	thread2.join();
}

void TestMultiThreading::provide_data() {
	for( int i = 0; i &lt; 10; ++i ) {
		boost::posix_time::time_duration td(0,0,2,0);
		boost::this_thread::sleep(td);

		mtx.lock();
		cout &lt;&lt; &quot;Thread 1 lock&quot; &lt;&lt; endl;
		var = i;
		cout &lt;&lt; &quot;Thread 1 unlock&quot; &lt;&lt; endl;
		mtx.unlock();

	}
}

void TestMultiThreading::process_data() {
	int local_var = -1;
	while( local_var != 9 ) {
		boost::posix_time::time_duration td(0,0,1,0);
		boost::this_thread::sleep(td);

		mtx.lock();
		cout &lt;&lt; &quot;Thread 2 lock&quot; &lt;&lt; endl;
		local_var = var;
		cout &lt;&lt; &quot;Thread 2 unlock&quot; &lt;&lt; endl;
		mtx.unlock();

		cout &lt;&lt; local_var &lt;&lt; endl;
	}
}

int main( int argc, const char* argv[] ) {
	printf( &quot;MultiThreading?\n&quot; );
	TestMultiThreading mt;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1929488</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1929488</guid><dc:creator><![CDATA[HändyÄndy]]></dc:creator><pubDate>Wed, 21 Jul 2010 09:54:29 GMT</pubDate></item></channel></rss>