I have created a class which includes a linked list and this class needs to have a destructor for deleting the linked list, which I have included however because the delete method itself calls the destructor I end up in an infinite recursive call situaction.
Here is the code:-
PolynomialNode::~PolynomialNode()
{
/*PolynomialNode* current_node_ptr = link;
PolynomialNode* header_ptr = link;
int index = 0;
if( link != NULL)
{
while( current_node_ptr != NULL)
{
index++;
current_node_ptr = current_node_ptr->get_link();
}
delete_nodes( &header_ptr, 0, index);
} */
PolynomialNode* current_node_ptr = link;
PolynomialNode* copy_ptr;
while( current_node_ptr != NULL)
{
copy_ptr = current_node_ptr->get_link();
current_node_ptr->set_link(NULL);
delete current_node_ptr;
current_node_ptr = copy_ptr;
}
}
Note I tried this with a recursive call - intentional for deleting the linked list and I still have the same problem.
Any help would be much appreciated.
NB: I know it's a recursive call because when I step through the debugger I can see it happening.