Proszę o pomoc sprawdzałem kod kilka razy wydaje mi się że wszystko ok i dalej nie działa ... dodaje wielomiany przeciążeniem operatora+
#include <iostream>
class Polynomial{
unsigned int degree;
double *coefficients;
public:
Polynomial(unsigned int n){
degree = n;
coefficients = new double[n+1];
for(unsigned int i=0; i<=n; i++){
coefficients[i]=0.0;
}
~Polynomial(){
delete coefficients;
}
friend Polynomial operator+(const Polynomial p1, const Polynomial p2);
};
Polynomial operator+(const Polynomial p1, const Polynomial p2){
unsigned int k = 0;
if ( p1.degree >= p2.degree) k = p1.degree;
else k = p2.degree;
Polynomial p3(k);
for( k ; k>=0; k--){
p3.coefficients[k] = p1.coefficients[k] + p2.coefficients[k];
}
return p3;
}
int main(int argc, char* argv[]){
Polynomial p1(2), p2(2), p3(2);
p3 = p1 + p2;
return 0;
}