Advertisement
Redee

Шаблонный Функтор c хранением состояния счетчика...

Jun 6th, 2016
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. ///////
  2. // Шаблонный Функтор c хранением состояния счетчика...
  3. ///
  4.  
  5. class Display
  6. {
  7.     __int64 _cnt;
  8.  
  9.     public:
  10.         Display(){ _cnt = 0; }
  11.  
  12.         template< typename T >
  13.         void operator()(T a)
  14.         {
  15.             cout << a << endl;
  16.             _cnt++;
  17.         }
  18.  
  19.         __int64 getCount(){ return _cnt; }
  20. };
  21.  
  22.  
  23. void main()
  24. {
  25.     Display diFnc;
  26.     diFnc(2);
  27.     diFnc("myCode");
  28.     diFnc(44.55);
  29.    
  30.     cout << "Amount of usage: " << diFnc.getCount() << endl;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement