I am trying to overload the + operator as a member function so that I can add two polynomial objects (which are linked lists) together and I keep getting an error message conversion from 'Polynomial*' to non-scalar type 'std::shared_ptr<Polynomial>' requested I don't understand what is causing this? I have declared two shared pointers for my Term objects so I don't understand why I can't do this for a polynomial object?
Polynomial Polynomial::operator+( const Polynomial &other ) const
{
shared_ptr<Polynomial> result = new Polynomial();
shared_ptr<Polynomial::Term> a = this->head;
shared_ptr<Polynomial::Term> b = other.head;
double sum = 0;
for(a; a != nullptr; a = a->next)
{
for(b; b != nullptr; b = b->next)
{
if(a->exponent == b->exponent)
{
sum = a->coeff + b->coeff;
result->head = shared_ptr<Term>(new Term( sum, a->exponent, result->head ));
cout << "function has found like terms" << endl;
}
else if(a->exponent != b->exponent)
{
result->head = shared_ptr<Term>(new Term( a->coeff, a->exponent, result->head ));
cout << "function is working" << endl;
}
}
}
result;
}
Aucun commentaire:
Enregistrer un commentaire