I want to insert a Node in a doubly linked list. I'm passed in the position, the new coefficient of the Polynomial and its power. I have no compile errors, but I get a Segmentation fault in linux (g++) and an Access Violation Writing Location when I run it with Visual Studio.
Unhandled exception at 0x00bd20ba in Program.exe: 0xC0000005: Access violation writing location 0xcdcdcdd9.
void Polynomial::insert( Term *pos, double newCoefficient, int power )
{
Term *newTerm = new Term; // create a new node to insert
// Link the new node to previous and next, given the position
newTerm->prev = pos->prev;
newTerm->next = pos;
newTerm->prev->next = newTerm; // Here's where I'm getting the error
newTerm->next->prev = newTerm;
// change the coefficient and power
newTerm->coefficient = newCoefficient;
newTerm->power = power;
}
What am I doing wrong and How do I fix this?
0xcdcdcdd9has debug-filler written all over it. validate your inputs before dereferencing them (or assigning them for that matter). - WhozCraig