<?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[std::for_each will nicht]]></title><description><![CDATA[<p>Mein testcode:</p>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;algorithm&gt;
#include &lt;iostream&gt;

int main()
{
	class Worker : public std::unary_function&lt;char, void&gt;
	{
	public:
		void operator()(char&amp; data) {data++;}
	};

	std::string text = &quot;ABCabc&quot;;

	std::cout &lt;&lt; text &lt;&lt; std::endl;

	std::for_each(text.begin(), text.end(), Worker());

	std::cout &lt;&lt; text &lt;&lt; std::endl;
}
</code></pre>
<pre><code>foreach.cpp:20:2: warning: no newline at end of file
foreach.cpp: In function ‘int main()’:
foreach.cpp:17: error: no matching function for call to ‘for_each(__gnu_cxx::__normal_iterator&lt;char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, __gnu_cxx::__normal_iterator&lt;char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, main()::Worker)’
</code></pre>
<p>Sagt mir, was ich falsch mache <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>EDIT://<br />
Scheint als wäre std::unary_function ein antikes Erbe, das in meiner Version von offline <a href="http://cplusplus.com" rel="nofollow">cplusplus.com</a> noch überlebt hat.</p>
<p>Folgendes Compiliert mit MS VC8 (wine 0.9.53)</p>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;algorithm&gt;
#include &lt;iostream&gt;

int main()
{
	class Worker
	{
	public:
		void operator()(char&amp; data) {data++;}
	};

	std::string text = &quot;ABCabc&quot;;

	std::cout &lt;&lt; text &lt;&lt; std::endl;

	std::for_each(text.begin(), text.end(), Worker());

	std::cout &lt;&lt; text &lt;&lt; std::endl;
}
</code></pre>
<p>G++ 4.2.1 bringt immer noch den selben Fehler</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/203185/std-for_each-will-nicht</link><generator>RSS for Node</generator><lastBuildDate>Wed, 07 Oct 2026 11:00:51 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/203185.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 19 Jan 2008 21:06:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to std::for_each will nicht on Sat, 19 Jan 2008 21:31:08 GMT]]></title><description><![CDATA[<p>Mein testcode:</p>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;algorithm&gt;
#include &lt;iostream&gt;

int main()
{
	class Worker : public std::unary_function&lt;char, void&gt;
	{
	public:
		void operator()(char&amp; data) {data++;}
	};

	std::string text = &quot;ABCabc&quot;;

	std::cout &lt;&lt; text &lt;&lt; std::endl;

	std::for_each(text.begin(), text.end(), Worker());

	std::cout &lt;&lt; text &lt;&lt; std::endl;
}
</code></pre>
<pre><code>foreach.cpp:20:2: warning: no newline at end of file
foreach.cpp: In function ‘int main()’:
foreach.cpp:17: error: no matching function for call to ‘for_each(__gnu_cxx::__normal_iterator&lt;char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, __gnu_cxx::__normal_iterator&lt;char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, main()::Worker)’
</code></pre>
<p>Sagt mir, was ich falsch mache <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>EDIT://<br />
Scheint als wäre std::unary_function ein antikes Erbe, das in meiner Version von offline <a href="http://cplusplus.com" rel="nofollow">cplusplus.com</a> noch überlebt hat.</p>
<p>Folgendes Compiliert mit MS VC8 (wine 0.9.53)</p>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;algorithm&gt;
#include &lt;iostream&gt;

int main()
{
	class Worker
	{
	public:
		void operator()(char&amp; data) {data++;}
	};

	std::string text = &quot;ABCabc&quot;;

	std::cout &lt;&lt; text &lt;&lt; std::endl;

	std::for_each(text.begin(), text.end(), Worker());

	std::cout &lt;&lt; text &lt;&lt; std::endl;
}
</code></pre>
<p>G++ 4.2.1 bringt immer noch den selben Fehler</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1439656</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1439656</guid><dc:creator><![CDATA[darthdespotism]]></dc:creator><pubDate>Sat, 19 Jan 2008 21:31:08 GMT</pubDate></item><item><title><![CDATA[Reply to std::for_each will nicht on Sat, 19 Jan 2008 21:30:51 GMT]]></title><description><![CDATA[<p>Du musst <code>Worker</code> leider aus der main rausziehen. Lokale Typen können keine Templateparameter sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1439666</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1439666</guid><dc:creator><![CDATA[finix]]></dc:creator><pubDate>Sat, 19 Jan 2008 21:30:51 GMT</pubDate></item><item><title><![CDATA[Reply to std::for_each will nicht on Sat, 19 Jan 2008 21:33:42 GMT]]></title><description><![CDATA[<p>Zu was les ich eigentlich gare nen Buch über templates?</p>
<p>Danke für den Tip, so geht's mal wieder (interessant, dass es MSVC trotzdem übersetzt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> )</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1439669</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1439669</guid><dc:creator><![CDATA[darthdespotism]]></dc:creator><pubDate>Sat, 19 Jan 2008 21:33:42 GMT</pubDate></item><item><title><![CDATA[Reply to std::for_each will nicht on Sat, 19 Jan 2008 21:35:16 GMT]]></title><description><![CDATA[<p>darthdespotism schrieb:</p>
<blockquote>
<p>EDIT://<br />
Scheint als wäre std::unary_function ein antikes Erbe, das in meiner Version von offline <a href="http://cplusplus.com" rel="nofollow">cplusplus.com</a> noch überlebt hat.</p>
</blockquote>
<p><a href="http://www.sgi.com/tech/stl/AdaptableUnaryFunction.html" rel="nofollow">Nein</a>.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1439672</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1439672</guid><dc:creator><![CDATA[finix]]></dc:creator><pubDate>Sat, 19 Jan 2008 21:35:16 GMT</pubDate></item><item><title><![CDATA[Reply to std::for_each will nicht on Sat, 19 Jan 2008 21:40:50 GMT]]></title><description><![CDATA[<p>Noch was gelernt. Dann bindet &lt;algorithm&gt; einfach nicht mehr &lt;functional&gt; ein beim MS VC und benötigt ist es nicht mehr für for_each.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1439675</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1439675</guid><dc:creator><![CDATA[darthdespotism]]></dc:creator><pubDate>Sat, 19 Jan 2008 21:40:50 GMT</pubDate></item><item><title><![CDATA[Reply to std::for_each will nicht on Sun, 20 Jan 2008 20:20:28 GMT]]></title><description><![CDATA[<p>darthdespotism schrieb:</p>
<blockquote>
<p>Zu was les ich eigentlich gare nen Buch über templates?</p>
<p>Danke für den Tip, so geht's mal wieder (interessant, dass es MSVC trotzdem übersetzt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> )</p>
</blockquote>
<p>Wenn du MSVC 8 die &quot;Language Extensions&quot; ausdrehst bekommst du folgenden Fehler: &quot;error C2918: 'main::Worker' : illegal use of local type in template instantiation&quot;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1440169</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1440169</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sun, 20 Jan 2008 20:20:28 GMT</pubDate></item></channel></rss>