<numeric> accumulate won't accept three inputs

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to use the std::accumulate function. When I compile the
following code I get: error C2780: '_Ty
std::accumulate(_InIt,_InIt,_Ty,_Fn2)' : expects 4 arguments - 3 provided.
It should accept three inputs as I've used below. I don't understand. I'd
really appreciate it if someone could set me straight. I've looked at the
declaration in numeric, there is a three input template as I've used. Also
in the help files included with MS VC++ there is an example as I've used the
function. I don't get it! Thanks in advance for any time and help you can
provide. I am using MS VC++ Version 7.1.3088 with .NET Framework ver.
1.1.4322 SP1

#include <iostream>
#include <numeric>
#include <list>

using namespace std;

double average(const list<double>&);

int main(){

list<double> lInput;
double dInput;

while(cin >> dInput){
lInput.push_back(dInput);
cout << "Average so far: " << average(lInput) << endl;
}

return 0;
}


double average(const list<double>& l){
return accumulate(l.begin(), l.end, 0.0) / l.size();
}
 
double average(const list<double>& l){
return accumulate(l.begin(), l.end, 0.0) / l.size(); //Error: missed params
}

Must be

double average(const list<double>& l){
return accumulate(l.begin(), l.end(), 0.0) / l.size();
}


--
Un saludo
Rodrigo Corral González [MVP]

FAQ de microsoft.public.es.vc++
http://rcorral.mvps.org
 
Thank you very much. I stared at the code, looked at examples, looked on the
web, etc. The answer was very obvious, but I just didn't see it. Thank you
for your reply and your time.

Saludos,
Ben R
 
Back
Top