Reputation: 156
Ive been trying to get this solved for quite a few hours, but I don't know how to get around this. I have a list of values in a list container like the following:
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
I have also created another list of pointers that point to every 4th element. So they point to the following:
[0,4,8,12]
I have a Method to return the end of the list of pointers. Like the following:
int* end() {return *(pointerlist.end()) ;};
This gives me "Runtime Error: Assertion Failed, List Iterater not dereferencable"
I understand that I am recieving this error because I am attempting to reach beyond the end of the list of pointers, But I would Like the have the value of the last element in this list. I have tried doing the following as well, but it just makes things worse.
int* end() {return *(pointerlist.end() - 1) ;};
Does anyone have any ideas how I can retrieve the last element in the list of pointers?
Upvotes: 1
Views: 218
Reputation: 249143
This should do it:
int* end() {
assert(!pointerlist.empty());
return pointerlist.back();
}
Upvotes: 1