Class SumSquaresClass

Lines 21–30 define the class template SumSquaresClass with an overloaded operator() that has two parameters and returns a value—the requirements for a binary function object. On the first call to the function object, the first argument will be the initial value of the total (which is supplied as the third argument to accumulate; 0 in this program) and the second argument will be the first element in array integers. All subsequent calls to operator receive as the first argument the result returned by the previous call to the function object, and the second argument will be the next element in the array. When accumulate completes, it returns the sum of the squares of all the elements in the array.

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.