I have a polynomial implementation in a linked list and want to do std::ostream overloading operation but it gives my an error that no match for ‘operator<<’ in ‘std::cout << p5’
That’s my implementation but when I test it through cout << p5 I get the aforementioned error.
UPDATE:
header file:
struct term{
double coef;
unsigned deg;
struct term * next;
};
class Polynomial {
public:
constructors etc
overloading functions
friend ostream& operator << (ostream& out,const term& object);
}
then in other file poly.cpp i have:
ostream & operator << (ostream& out, const Polynomial object){
term* q = object.getptr();
if (object.getptr() == NULL)
out << "( )";
else
while(q != NULL)
{
out << q->coef << "x^" << q->deg << " ";
q = q->next;
}
return out;
}
in main.cpp
Polynomial p5, then added some terms and cout << p5 but I get errors.
I think it’s your declarations which are causing the problem:
and
These don’t match. One is using a
termobject and the latter is using aPolynomialobject. I’m assuming you want this function to use a term object because the function uses data memebers specific to the structterm. So change the latter to accept atermobject: