overload + operator to add 2 polynomials C++
<p>I'm writing the function to add 2 polynomials together, the case where 2 polynomials have the same amount of highest degree (all terms need not to be entered) works fine, but the case where two polys have different degree is not working, the function somehow store some big value as the coefficients</p>

<p>This is the function</p>

<pre><code>// overload +
Polynomial Polynomial::operator+(const Polynomial &amp;right)
{
    // get the highest exponent value for result
    int highestExp = 0;
    if (maxExp &lt; right.maxExp)
        highestExp = right.maxExp;
    else if (maxExp &gt;= right.maxExp)
        highestExp = maxExp;

    Polynomial res;
    res.setPolynomial(highestExp);

    for (int coeff=0; coeff &lt; highestExp; coeff++)
            res.poly[0][coeff] = poly[0][coeff] + right.poly[0][coeff];

    return res;
}
</code></pre>

<p>for example, 
case1: highest exps are equal</p>

<pre><code>The first (original) polynomial is:
 - 4x^0 + x^1 + 4x^3 - 3x^4
The second polynomial is:
 - x^0 - x^3
The result polynomial is:
 - 5x^0 + x^1 + 3x^3 - 3x^4
</code></pre>

<p>case2: highest exponents are not equal</p>

<pre><code>The first (original) polynomial is:
 - 4x^0 + x^1 + 4x^3 - 3x^4 (highest exp = 4)
The second polynomial is:
 - x^0 - x^3 (highest exp = 5)
The result polynomial is:
 - 5x^0 + x^1 + 3x^3 - 3x^4 - 33686019x^5 (highest exp = 5)
</code></pre>

<p>please help!</p>

<p>Update: Polynomial class</p>

<pre><code>class Polynomial
{
private:
    int **poly;
    int maxExp;
    void createPolynomialArray(int);
public:
    Polynomial();
    Polynomial(int); // constructor
    Polynomial(const Polynomial &amp;); // copy constructor
    ~Polynomial(); // destructor

    // setter
    void setCoefficient(int,int);
    void setPolynomial(int);

    // getters
    int getTerm() const; 
    int getCoefficient(int,int) const; 

    // overloading operators
    void operator=(const Polynomial &amp;); // assignment
    Polynomial operator+(const Polynomial &amp;); // addition    
}
</code></pre>
