<?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[Template For_each problem]]></title><description><![CDATA[<p>Hall Kann den fehler hinsichtlich for_each nicht finden, stimmt was an meine DecreaseTime klasse nicht?</p>
<p>Fehler:</p>
<pre><code>d:\Projekte\WinCC_TagReduce\ANSI C Debug\eventqueue\eventqueue.cpp(43): error C2784: '_Fn1 std::for_each(_InIt,_InIt,_Fn1)' : could not deduce template argument for 'overloaded function type' from 'overloaded function type'

d:\Projekte\WinCC_TagReduce\ANSI C Debug\eventqueue\eventqueue.cpp(43): error C2914: 'std::for_each' : cannot deduce template argument as function argument is ambiguous
</code></pre>
<pre><code class="language-cpp">#include &quot;stdafx.h&quot;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

template&lt;class T&gt; 
class DecreaseTime{

   T m_dIntervall;   // The value to multiply by

public:
   // Constructor initializes the value to multiply by
    DecreaseTime(const T&amp; dVal ) : m_dIntervall ( dVal ) {
   }

   // The function call for the element to be multiplied
   void operator ( ) (T &amp;dTime ) const {
      dTime-= m_dIntervall;
   }
};

int _tmain(int argc, _TCHAR* argv[]){

	std::vector&lt;double&gt; test;
	for(int i=0; i&lt; 10; i++)
		test.push_back(i*2);

	while(!test.empty()){

		std::sort(test.begin(),test.end(),std::less&lt;double&gt;());
		printf(&quot;\n--------- Iteration --------- Events: %i \n&quot;,test.size());
		for(std::vector&lt;double&gt;::iterator it= test.begin(); it != test.end(); it++)
			printf(&quot;%f \t&quot;, (*it));
		std::for_each(test.begin,test.end(),DecreaseTime&lt;double&gt;(1.0)); //&lt;- FEHLER
		for(std::vector&lt;double&gt;::iterator it= test.begin(); (*it)&lt;= 0;);
		}

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/217940/template-for_each-problem</link><generator>RSS for Node</generator><lastBuildDate>Sat, 10 Oct 2026 06:53:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/217940.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 14 Jul 2008 06:15:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Template For_each problem on Mon, 14 Jul 2008 06:15:51 GMT]]></title><description><![CDATA[<p>Hall Kann den fehler hinsichtlich for_each nicht finden, stimmt was an meine DecreaseTime klasse nicht?</p>
<p>Fehler:</p>
<pre><code>d:\Projekte\WinCC_TagReduce\ANSI C Debug\eventqueue\eventqueue.cpp(43): error C2784: '_Fn1 std::for_each(_InIt,_InIt,_Fn1)' : could not deduce template argument for 'overloaded function type' from 'overloaded function type'

d:\Projekte\WinCC_TagReduce\ANSI C Debug\eventqueue\eventqueue.cpp(43): error C2914: 'std::for_each' : cannot deduce template argument as function argument is ambiguous
</code></pre>
<pre><code class="language-cpp">#include &quot;stdafx.h&quot;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

template&lt;class T&gt; 
class DecreaseTime{

   T m_dIntervall;   // The value to multiply by

public:
   // Constructor initializes the value to multiply by
    DecreaseTime(const T&amp; dVal ) : m_dIntervall ( dVal ) {
   }

   // The function call for the element to be multiplied
   void operator ( ) (T &amp;dTime ) const {
      dTime-= m_dIntervall;
   }
};

int _tmain(int argc, _TCHAR* argv[]){

	std::vector&lt;double&gt; test;
	for(int i=0; i&lt; 10; i++)
		test.push_back(i*2);

	while(!test.empty()){

		std::sort(test.begin(),test.end(),std::less&lt;double&gt;());
		printf(&quot;\n--------- Iteration --------- Events: %i \n&quot;,test.size());
		for(std::vector&lt;double&gt;::iterator it= test.begin(); it != test.end(); it++)
			printf(&quot;%f \t&quot;, (*it));
		std::for_each(test.begin,test.end(),DecreaseTime&lt;double&gt;(1.0)); //&lt;- FEHLER
		for(std::vector&lt;double&gt;::iterator it= test.begin(); (*it)&lt;= 0;);
		}

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1546895</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1546895</guid><dc:creator><![CDATA[C++Lehrling_]]></dc:creator><pubDate>Mon, 14 Jul 2008 06:15:51 GMT</pubDate></item><item><title><![CDATA[Reply to Template For_each problem on Mon, 14 Jul 2008 06:22:59 GMT]]></title><description><![CDATA[<p>Mit DecreaseTime ist alles in Ordnung. Bei begin fehlen die Klammern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1546897</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1546897</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Mon, 14 Jul 2008 06:22:59 GMT</pubDate></item></channel></rss>