I am trying to loop through a polynomial using the iterator from the STL but it says i am dereferencing the iterator somewhere but i can not spot it. I have pin pointed the error to the return of the following code.

Polynom& Polynom :: AddPoly( const Polynom &a)
{
	list<PolyTerm>::const_iterator i = a.getHead();
	PolyTerm temp;
	for( i = a.getHead(); i != a.getTail(); ++i)
	{
		temp.Coeff = i->Coeff;
		temp.Exponent = i->Exponent;
		addTerm(temp);
}
	return *this;
}

addTerm is a function that adds the passed term to the list.
Polyterm is a struct with Coeff and Exponent as members.

Recommended Answers

All 2 Replies

Can you post a very short ( < 30 lines) piece of compilable code that demonstrates the problem?

Does the getTail() return the last element or one passed the last element? Is it valid to do this cout << (a.getTail())->Coeff << endl; Also what is the exact error message?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.