Monday, 15 June 2015

c++ - List iterator erase "Debug assertion failed" -



c++ - List iterator erase "Debug assertion failed" -

i have 2 std::lists. want delete items list 1 , insert in 2nd , vice versa. code not working (getting access violation , "list iterator not dereferencable")

for ( std::list<item *>::iterator = list1.begin(); != list1.end(); ++it ) { = list1.erase( ); list2.push_back( *it ); } = list1.begin(); = list2.erase( ); // because lastly element not deleted in above loop list2.push_back( *it );

symmetrical code 2nd method. manage transfer items between 2 lists 1 time, next error.

any help?

this , efficiently done std::list's swap fellow member function:

list1.swap(list2);

this has constant time complexity.

c++ list iterator

No comments:

Post a Comment