title: c++ oop problem with this how initial "unable to read memory"
body: <p>I have a problem as shown on the following image <img src="https://i.stack.imgur.com/g3b8c.png" alt="image"></p>
  
  <p>I have added all the code of the monom.cpp  , 
  Probably the problem that I did not set the temp well is the help how to set temp, the result that i should return it's polinom = 0;it's 
  The degree of the polynomial and for example I add polynomial x ^ 2 + 1
  The degree of the polynomial is 2</p>
  
  <pre><code>void  Polinom::add(const Monomial const &amp; monomial)
  
  int base = monomial.getCoff();
  int exp = monomial.getExpo();
  bool foundBase = false;
  Monomial* temp = new Monomial[size + 1];
  
  for (int i = 0; i &lt; size; i++)
  {
      Monomial monom;
           monom = monomials[i];
      if (exp == monom.getExpo())
      {
          monom.setCoff(base + monom.getCoff());
          foundBase = true;
      }
      temp[i] = monom;
  }
  if (!foundBase)
  {
      monomials[size] = Monomial(monomial);
      delete[] monomials;
      monomials = temp;
  }
  else
  {
      delete[] temp;
  }
  </code></pre>
  
  <p>Monomial.cpp</p>
  
  <pre><code>int Monomial::counter = 0;
  Monomial::Monomial()
  {
  setCoff(1);
  setExpo(0);
  counter++;
  }
  Monomial::Monomial(int a)
  {
   setCoff(a);
   setExpo(0);
   counter++;
  }
   Monomial::Monomial(int a, int b)
   {
    setCoff(a);
    setExpo(b);
    counter++;
   }
   Monomial::~Monomial()
   {
    counter--;
   }
   void Monomial::setCoff(int x)
   {
   coff = x;
   }
    void Monomial::setExpo(int x)
   {
   expo = x;
   }
    int Monomial::getCoff() const
   {
  return coff;
   }
   int Monomial::getExpo() const
   {
  return expo;
  }
  
  int Monomial::getNumberOfMonomials()
  {
  return counter;
   }
  
   const Monomial&amp; Monomial:: operator = (const Monomial&amp; right)
   {
    coff = right.coff;
    expo = right.expo;
    return (*this);
    }
  
  
   string Monomial:: operator+(const Monomial&amp; right)
   {
     if (right.getExpo() == this-&gt;getExpo()) {
  
        this-&gt;setCoff(this-&gt;getCoff() + right.getCoff());
  
          return "True";
      }
  
     return "False";
    }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/B4wq0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B4wq0.png" alt="enter image description here"></a></p>