Advertisement
andruhovski

Functor Demo

Mar 13th, 2015
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. // functor_demo.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <string>
  6. #include <iostream>
  7. #include <algorithm>
  8. #include <vector>
  9. #include <functional>
  10.  
  11. using namespace std;
  12. class Student {
  13. public:
  14.     string firstName;
  15.     string lastName;
  16.     void show() { cout << firstName << " " << lastName << endl; }
  17. };
  18.  
  19. int _tmain(int argc, _TCHAR* argv[])
  20. {
  21.     vector<Student> Grp(3);
  22.     Grp[0].firstName="A";
  23.     Grp[1].firstName="B";
  24.     Grp[2].firstName="C";
  25.     Grp[0].lastName="A";
  26.     Grp[1].lastName="B";
  27.     Grp[2].lastName="C";
  28.     for_each(Grp.begin(),Grp.end(),
  29.         mem_fun_ref(&Student::show));
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement