Lines 43–44 call function accumulate
with a pointer to function sumSquares
as its last argument. Similarly, the statement in lines 51–52 calls accumulate
with an object of class SumSquaresClass
as the last argument. The expression SumSquaresClass<int>()
creates (and calls the default constructor for) an instance of class SumSquaresClass
(a function object) that’s passed to accumulate
, which invokes the function operator()
. Lines 51–52 could be written as two separate statements, as follows:
SumSquaresClass< int > sumSquaresObject;
result = accumulate( integers.cbegin(), integers.cend(),
0, sumSquaresObject );
The first line defines an object of class SumSquaresClass
. That object is then passed to accumulate
.