I have the following class. It has a static member _list
to be shared by all instances of the class, which will be created within Class_f()
. I want to use the erase function in order to erase say the last element of _list
.
class myClass
{
private:
static list<int> _list;
public:
//constructors,destructors
void Class_f();
}
list<int> myCLass::_list;
void myClass::Class_f()
{
//..some code
list<int>::iterator it1;
it1=_list.end (); //erase for instance the last element _list
it1=_list.erase(it1);
//more code
}
However when compiling it outputs me an error with the message "list iterator not incrementable". Why is it giving me this error? In addition, why can't I use something simpler like _list.erase(_list.end())
so as to avoid creating an iterator.