Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercise 10_32.cc (G++ giving error on the accumulate algorithm) #840

Open
yapkm01 opened this issue Oct 28, 2023 · 0 comments
Open

Exercise 10_32.cc (G++ giving error on the accumulate algorithm) #840

yapkm01 opened this issue Oct 28, 2023 · 0 comments

Comments

@yapkm01
Copy link

yapkm01 commented Oct 28, 2023

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.

https://en.cppreference.com/w/cpp/algorithm/accumulate

@yapkm01 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant