×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: C++
Posted by: Massi Massi
Added: Sep 22, 2016 10:32 AM
Modified: Sep 22, 2016 11:11 AM
Views: 7
Tags: no tags
  1.  
  2. template<typename T, unsigned int size>
  3. class TabIterator {
  4.   public:
  5.     TabIterator() {
  6.       it = new T;
  7.       std::cout << "TabIterator par défaut \n";
  8.     }
  9.  
  10.     TabIterator(T * pT) {
  11.       it = pT;
  12.       std::cout << "TabIterator par défaut \n";
  13.     }
  14.  
  15.     TabIterator<T, size> & operator ++() {
  16.       it = it + 1;
  17.       std::cout << "++ Surcharge" << std::endl;
  18.       return *this;
  19.     }
  20.  
  21.     T operator *() {
  22.       return *it;
  23.     }
  24.  
  25.     TabIterator<T, size> operator ++(int a) {
  26.       TabIterator<T, size> temp = *this;
  27.       it = it + 1;
  28.       std::cout << "Surcharge ++" << std::endl;
  29.       return temp;
  30.     }
  31.  
  32.     bool operator !=(const TabIterator<T, size> & TbI) {
  33.       if (TbI.it != it)
  34.         return true;
  35.       return false;
  36.     }
  37.  
  38.     ~TabIterator() {
  39.       std::cout << "Destruction TabIterator \n";
  40.     }
  41.  
  42.     template<typename T2, unsigned int size2>
  43.     friend std::ostream & operator <<(std::ostream & os, const TabIterator<T2, size2> & TbI);
  44.  
  45.   private:
  46.     T * it;
  47. };
  48.  
  49. template<typename T2, unsigned int size2>
  50. std::ostream & operator <<(std::ostream & os, const TabIterator<T2, size2> & TbI) {
  51.   os << "L'itérateur pointe sur " << TbI.it << "\n";
  52.   return os;
  53. }
  54.  
  55.  
  56.