fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <functional>
  4. #include <string>
  5. using namespace std;
  6.  
  7. struct c1{
  8. vector<int> v;
  9. c1(vector<int> val):v(val){}
  10.  
  11. void modifyV(function<string (int)> functionHandle) {
  12. if(functionHandle) {
  13. for_each(v.begin(), v.end(), [&](int e){cout<<functionHandle(e);});
  14. }
  15. }
  16. };
  17.  
  18. struct c2{
  19. int record;
  20. c2():record(0){};
  21. string c2func(int val) {
  22. record = max(record, val);
  23. return val%2?"odd ":"mean ";
  24. }
  25. void disp() {
  26. cout<<"\nmax number is "<<record;
  27. }
  28. };
  29.  
  30. int main() {
  31. vector<int> v{1,2,3,4,5};
  32. c1 t(v);
  33. c2 t2;
  34. t.modifyV([&](int val){return t2.c2func(val);});
  35. t2.disp();
  36. return 0;
  37. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
odd mean odd mean odd 
max number is 5