You need to figure out which monomial exponents are in both polynomials and add their coefficients. Then you need to figure out which monomial exponents are in only 1 polynomial, and essentially copy that monomial to the sum.
Your function declaration has some problems, though. Because you declared it as a member function, it already has a poly associated with it. When you have 2 other poly arguments, that makes 3 polys that you have to deal with. Also, you have no return value, so you can't return the sum. In the following code:
1 2 3 4 5 6
|
poly a(1);
poly b(2);
poly c(3);
/* initialization here */
a.add(b, c);
|
it is possible that you want a to contain the sum of b and c, but I suspect what you want to do is
a = b.add(c);
In that case, you want to declare the add function as
poly add(const poly& v) const;
A couple other things to think about. Will the exponent always be an integer? If so, change the type to int. Same thing with coefficient (but there is more chance that the coefficient will have non-int values).
Note: I hesitate to bring this up because I don't want to confuse things any further, but now that I know more of what you are trying to do, I'm not sure I would use a vector of monomials. I would probably use a std::map, where each entry represents a monomial (the key is the exponent and the value is the coefficient). The map would make finding common exponents a little bit easier, and it will automatically sort the monomial terms in order of their exponent values.