#include <list>
using namespace std;
int main() {
list<int> l;
l.push_front(1);
list<int>::const_iterator it = l.begin();
l.erase(it);
return 0;
}
Kompilacja jako C++11 (!) wyrzuca mi następujące błędy:
prog.cpp: In function ‘int main()’:
prog.cpp:9:12: error: no matching function for call to ‘std::list<int>::erase(std::list<int>::const_iterator&)’
l.erase(it);
^
prog.cpp:9:12: note: candidates are:
In file included from /usr/include/c++/4.8/list:64:0,
from prog.cpp:1:
/usr/include/c++/4.8/bits/list.tcc:108:5: note: std::list<_Tp, _Alloc>::iterator std::list<_Tp, _Alloc>::erase(std::list<_Tp, _Alloc>::iterator) [with _Tp = int; _Alloc = std::allocator<int>; std::list<_Tp, _Alloc>::iterator = std::_List_iterator<int>]
list<_Tp, _Alloc>::
^
/usr/include/c++/4.8/bits/list.tcc:108:5: note: no known conversion for argument 1 from ‘std::list<int>::const_iterator {aka std::_List_const_iterator<int>}’ to ‘std::list<int>::iterator {aka std::_List_iterator<int>}’
In file included from /usr/include/c++/4.8/list:63:0,
from prog.cpp:1:
/usr/include/c++/4.8/bits/stl_list.h:1193:7: note: std::list<_Tp, _Alloc>::iterator std::list<_Tp, _Alloc>::erase(std::list<_Tp, _Alloc>::iterator, std::list<_Tp, _Alloc>::iterator) [with _Tp = int; _Alloc = std::allocator<int>; std::list<_Tp, _Alloc>::iterator = std::_List_iterator<int>]
erase(iterator __first, iterator __last)
^
/usr/include/c++/4.8/bits/stl_list.h:1193:7: note: candidate expects 2 arguments, 1 provided
Z tego, co zrozumiałem, to kompilator chce, żebym podał zwykły iterator, a nie const_iterator. Bzdura jakaś, w dokumentacji http://www.cplusplus.com/reference/list/list/erase/ jest napisane, że list::erase akceptuje const_iterator jako argument w C++11!
Więc ostatecznie, nie pojmuję.