RE: [Dev-C++] stl accumulate question
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ho...> - 2002-09-04 23:50:52
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of h.r...@gm...
> Sent: Thursday, September 05, 2002 1:20 AM
> To: dev...@li...
> Subject: [Dev-C++] stl accumulate question
>
>
> Hi list,
>
> i want to replace the following code:
>
> typedef vector<double>::iterator it;
>
> for(it i = TMW.begin(); i != TMW.end(); i++) {
> sx += *i;
> sxx += sqr(*i);
> }
>
> with
>
> sx = accumulate(TMW.begin(), TMW.end(), 0.0);
> sxx = accumulate(TMW.begin(), TMW.end(), 0.0, sqr);
> [...]
>
> def of sqr:
>
> template<class T>
> inline T sqr(T x) { return x * x; }
>
> but sxx = .... does not compile.
>
> The error message:
> 55 E:\dev\dev-c++\proj2\procabi.cpp
> no matching function for call to `accumulate (double *,
> double *, double,
> {unknown type})'
>
> Why that ???
#include <numeric>
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|