I am trying to create a function that adds two polynomial coefficients together, basically i have a class polynomial10 and i am creating a function add to add these coefficients together to create a new instance of the class polynomial 10.
Unfortunately when I try to declare the function there comes an error.
Follows the code:
polynomial10 polynomial10::adiciona (polynomial10& p) {
int t = size(coef);
int t2= size(p.coef);
if (t>t2) {
vector<double> coef_r(t,0);
for (int i = 0; i < t; i++) {
if (i<=t2) {
coef_r[i] += coef[i]+p.coef[i];
}
else {
coef_r[i] += coef[i];
}
}}
else {
vector<double> coef_r(t2,0);
for (int i = 0; i < t2; i++) {
if (i<=t) {
coef_r[i] += coef[i]+p.coef[i];
}
else {
coef_r[i] += p.coef[i];
}
}
}
polynomial10 p3(coef_r);
return p3;
}
class polynomial10 {
public:
vector <double> coef;
polynomial10( vector <double>& c );
double evaluate(double x);
polynomial10 adiciona(polynomial10 p);
};
The function evaluates evaluate the value of the polynomial for a given x and is working properly as previously tested.
I get the following message from VSCode “declaration is incompatible with “polynomial10 polynomial10::adiciona(polynomial10 p)”