c++ - Iterator for a container of a custom object -
if i've built class want contain inside, example set, how iterate through said set? say
std::set<customobject>::iterator
i thought that, i'm getting following series of errors...
drawing.h:110: error: no match ‘operator=’ in ‘it = ((object*)this)->object::objects. std::vector<_tp, _alloc>::begin [with _tp = object, _alloc = std::allocator<object>]()’ /usr/include/c++/4.2.1/bits/stl_tree.h:225: note: candidates are: std::_rb_tree_const_iterator<object>& std::_rb_tree_const_iterator<object>::operator=(const std::_rb_tree_const_iterator<object>&) drawing.h:110: error: no match ‘operator!=’ in ‘it != ((object*)this)->object::objects. std::vector<_tp, _alloc>::end [with _tp = object, _alloc = std::allocator<object>]()’ /usr/include/c++/4.2.1/bits/stl_tree.h:292: note: candidates are: bool std::_rb_tree_const_iterator<_tp>::operator!=(const std::_rb_tree_const_iterator<_tp>&) const [with _tp = object] drawing.h:111: error: ‘struct std::_rb_tree_const_iterator<object>’ has no member named ‘sketch’
here's code:
void draw_in_place() { place(); std::set<object>::const_iterator it; for(it = objects.begin(); != objects.end(); it++){ *it.draw_in_place(); } }
((object*)this)->object::objects. std::vector<_tp, _alloc>::begin
objects
apparently std::vector<object>
, not std::set<object>
. therefore need use std::vector<object>::const_iterator
.
*it.draw_in_place();
this incorrect: need dereference iterator access element first, use element:
(*it).draw_in_place(); // or it->draw_in_place();
Comments
Post a Comment