Make sure that elem
is a pointer that can be dereferenced, and that it's not either pointing to some invalid location in memory, or that it's not NULL. It seems that you have some type of linked list, and you are attempting to access a list-node that is two nodes away from the current node pointed to by ptr
. Either that node may not exist, and therefore sig
is an invalid pointer, or the node member elem
is an invalid pointer. Either way, you should definitely check pointers before you attempt to dereference so many steps. In fact, this may best be done with something like a for loop such as:
NodoL* temp = ptr;
for (int i=0; i < NUMBER; i++)
{
if (temp->sig == NULL)
break;
temp = temp->sig;
}
cout << *temp->elem << endl;
That way you will either pass through a certain NUMBER
of pre-specified nodes in the list from where you're currently at, or you will terminate the for-loop early because you've reached the end of the list.