// A program that illustrate the difference between the plus operator // and a function of two arguments that adds the arguments together. #include #include #include // accumulate #include // plus int main(){ using namespace std; // We make a list of doubles, and insert some numbers in the list: list lst; for(int i = 1; i <= 10; i++) lst.push_back(i); // 1, 2, ..., 10 // An operator is NOT a first class entity in C++: double res = accumulate(lst.begin(), lst.end(), 0.0, + ); // error: expected primary-expression .... // We must make an object which serves as a binary plus function: double res = accumulate(lst.begin(), lst.end(), 0.0, plus{}); cout << "The plus accumulation is: " << res << endl; // 55 }