Advertisement
wowonline

Untitled

Mar 19th, 2022
631
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <vector>
  2. #include <iostream>
  3. #include <cstdint>
  4. #include <algorithm>
  5.  
  6. class Accum {
  7.    
  8.     public:
  9.         int sum;
  10.         Accum(int s) {
  11.             sum = s;
  12.         }
  13.  
  14.         void operator() (int &value) {
  15.             sum += value;
  16.             std::cout << sum << std::endl;
  17.         }
  18. };
  19.  
  20.  
  21. int main()
  22. {
  23.     std::vector <int> v{1, 2, 3, 4, 5};
  24.  
  25.     Accum inst(2);
  26.     std::for_each(v.begin(), v.end(), inst);
  27.     std::cout << inst.sum;
  28.  
  29. }
Advertisement
RAW Paste Data Copied
Advertisement