You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As per your code, i am getting errors on the accumulate algorithm as shown below.
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <numeric>
#include "include/Sales_data.h"
using namespace std;
int main() {
istream_iterator<Sales_data> in_iter(cin), in_eof;
vector<Sales_data> vec;
while (in_iter != in_eof)
vec.push_back(*in_iter++);
sort(vec.begin(), vec.end(), compareIsbn);
for (auto& v: vec) {
cout << v << endl;
}
for (auto beg = vec.cbegin(), end = beg; beg != vec.cend(); beg = end) {
end = find_if(beg, vec.cend(), [beg](const Sales_data &item){ return item.isbn() != beg->isbn(); });
cout << accumulate(beg, end, Sales_data(beg->isbn())) << endl; // ERROR HERE!
}
return 0;
}
Errors:
In template: invalid operands to binary expression ('typename std::remove_reference<Sales_data &>::type' ..
Can you please explain how you managed to compile without errors? I checked this algorithm, and i don't see any issue based on the algorithm available parameters as in the cppreference site.
The text was updated successfully, but these errors were encountered:
yapkm01
changed the title
Exercise 10_32.cc (GCC giving error on the accumulate algorithm)
Exercise 10_32.cc (G++ giving error on the accumulate algorithm)
Oct 29, 2023
As per your code, i am getting errors on the accumulate algorithm as shown below.
Errors:
In template: invalid operands to binary expression ('typename std::remove_reference<Sales_data &>::type' ..
Can you please explain how you managed to compile without errors? I checked this algorithm, and i don't see any issue based on the algorithm available parameters as in the cppreference site.
https://en.cppreference.com/w/cpp/algorithm/accumulate
The text was updated successfully, but these errors were encountered: