Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. // bez =int
  7. template <typename typ>
  8. struct Gruszka
  9. {
  10.  
  11.     // brakuje () i.e. operator () (args..)
  12.     void operator ()(const typ x) const
  13.     {
  14.         cout << 2*x << endl;
  15.     }
  16. };
  17.  
  18. int main()
  19. {
  20.     vector <int> myVec;
  21.     myVec.push_back(5);
  22.     myVec.push_back(12);
  23.     myVec.push_back(521);
  24.     myVec.push_back(9);
  25.  
  26.     vector <int>::iterator it;
  27.  
  28.     for(it = myVec.begin(); it!= myVec.end();it++)
  29.     {
  30.         cout << *it << endl;
  31.     }
  32.  
  33.     for_each(myVec.begin(),myVec.end(),Gruszka <int>());
  34.     //                                          ^int
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement