title: Polynomial operations using operator overloading
body: <p>I'm trying to use operator overloading to define the basic operations (+,-,*,/) for my polynomial class but when i run the program it crashes and my computer frozes.</p>
  
  <p><strong>Update4</strong></p>
  
  <p>Ok. i successfully made three of the operations, the only one left is division.</p>
  
  <p>Here's what I got:</p>
  
  <pre><code>polinom operator*(const polinom&amp; P) const
  {
      polinom Result;
      constIter i, j, lastItem = Result.poly.end();
      Iter it1, it2, first, last;
      int nr_matches;
  
      for (i = poly.begin() ; i != poly.end(); i++) {
           for (j = P.poly.begin(); j != P.poly.end(); j++)
                Result.insert(i-&gt;coef * j-&gt;coef, i-&gt;pow + j-&gt;pow);
      }
  
      Result.poly.sort(SortDescending());
  
      lastItem--;
  
      while (true) {
          nr_matches = 0;
  
          for (it1 = Result.poly.begin(); it1 != lastItem; it1++) {
               first = it1;
               last = it1;
               first++;
               for (it2 = first; it2 != Result.poly.end(); it2++) { 
                    if (it2-&gt;pow == it1-&gt;pow) {
                        it1-&gt;coef += it2-&gt;coef;
                        nr_matches++;
                    }
               }
  
               nr_matches++;
               do {
                  last++;
                  nr_matches--;
               } while (nr_matches != 0);
  
               Result.poly.erase(first, last);
          }   
          if (nr_matches == 0)
              break;
      }     
  
      return Result;
  }
  </code></pre>