Advertisement
Guest User

Untitled

a guest
Oct 20th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class CustomIter {
  6. public:
  7.     CustomIter(int index=0) : index(index) {}
  8.  
  9.     CustomIter &operator++() {
  10.         cout << "Prefix" << endl;
  11.         ++index;
  12.         return *this;
  13.     }
  14.  
  15.     CustomIter operator++(int) {
  16.         CustomIter copy(index);
  17.         ++index;
  18.         cout << "Postfix" << endl;
  19.         return copy;
  20.     };
  21.    
  22.     int operator*() {
  23.         return index;
  24.     }
  25.    
  26. private:
  27.     int index;
  28. };
  29.  
  30. int main()
  31. {
  32.     CustomIter i;
  33.    
  34.     ++i;
  35.     i++;
  36.    
  37.     for (CustomIter i; *i != 5; ++i)
  38.         cout << *i << endl;
  39.    
  40.     for (CustomIter i; *i != 5; i++)
  41.         cout << *i << endl;
  42.    
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement