using accumulate in C++ with a const function as parameter

  accumulate, c++, stl

I couldnt find any solution, so Im posting a new topic.
I have to use accumulate with a const function as a parameter (doing some practice for a test):

  1. get_skills() – returns a list of skills and is defined as:

    const vector<string>& get_skills() const;
    
  2. I have to return a sum of the lengths of all skills

What I have tried:

double sum1 = accumulate(tmpObj.get_skills().begin(), tmpObj.get_skills().end(), 0., [](const string& s, const double& sum){return s.size() + sum;});

and I and up with:

 no matching function for call to object of type lambda
 note: candidate function not viable: no known conversion from 'double' to 'const std::__cxx11::string' (aka 'const basic_string<char>') for 1st argument

could somebody please explain what to use as lambda (I tried with tmpObj& but didnt change anything)
and what is causing the "no known conversion from ‘double’ to ‘const std::__cxx11::string’

thank you in advance!

Source: Windows Questions C++

LEAVE A COMMENT