Template For_each problem
-
Hall Kann den fehler hinsichtlich for_each nicht finden, stimmt was an meine DecreaseTime klasse nicht?
Fehler:
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#include "stdafx.h" #include <vector> #include <algorithm> template<class T> class DecreaseTime{ T m_dIntervall; // The value to multiply by public: // Constructor initializes the value to multiply by DecreaseTime(const T& dVal ) : m_dIntervall ( dVal ) { } // The function call for the element to be multiplied void operator ( ) (T &dTime ) const { dTime-= m_dIntervall; } }; int _tmain(int argc, _TCHAR* argv[]){ std::vector<double> test; for(int i=0; i< 10; i++) test.push_back(i*2); while(!test.empty()){ std::sort(test.begin(),test.end(),std::less<double>()); printf("\n--------- Iteration --------- Events: %i \n",test.size()); for(std::vector<double>::iterator it= test.begin(); it != test.end(); it++) printf("%f \t", (*it)); std::for_each(test.begin,test.end(),DecreaseTime<double>(1.0)); //<- FEHLER for(std::vector<double>::iterator it= test.begin(); (*it)<= 0;); } return 0; }
-
Mit DecreaseTime ist alles in Ordnung. Bei begin fehlen die Klammern.