I created a struct with two fields of type Point3f
(which is inherited from another header).
struct C_Cell {
Point3f min, max;
};
then I created a vector of C_Cell
std::vector< C_Cell> grid;
and I have filled through grid.push_back(c)
where c
is a C_Cell
.
Now, when I try to iterate the vector, through
for (std::vector<C_Cell>::iterator it = grid.begin() ; it != grid.end(); ++it)
during debugging, the type of it isn't C_Cell
but Point3f
, which is the type of the field, moreover empty.
How can I iterate correctly, in such a way to obtain a single element of type C_Cell
?
Thanks ( and sorry for my english! :) )
You have to dereference the iterator and use it like
(*it).min
or
(*it).max
or, without de-referencing,
it->min
The type of the dereferenced iterator (*it)
SHOULD be C_Cell
, as that's how iterators work, their operator*
returns a reference to an object of the underlying type of the container. Iterators behave very much like regular pointers (although they are not regular pointers, but proxy classes), you can increment/dereference etc.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.