iterator of std::array within a vector dereferencing


1
2
3
4
5
std::vector<std::array<sf::RectangleShape,number_of_blocks_per_shape>>::const_iterator iter;
    for ( iter = forms.begin(); iter != forms.end(); iter++ )
    {
        //accessing the data in the vector
    }


Ive been figuring this out, but i dont know how to access all elements in a 2D container through iterator.
Last edited on
Your 'iter' is an iterator to vector element. By dereferencing an iterator you access the pointed to object. In your case vector element is a std::array.

If you had vector of strings, how would you operate on them?
If you had single array object, how would you access its elements?

C++11 has auto and range-based loop too:
1
2
3
4
5
for ( const auto & arr : forms ) {
  for ( const auto & shape : arr ) {
    // shape is a reference to a RectangleShape object
  }
}

okay thanks @keskiverto
 passing 'const value_type {aka const sf::RectangleShape}' as 'this' argument of 'void sf::Transformable::move(float, float)' discards qualifiers [-fpermissive]|


why i keep getting this error?
Topic archived. No new replies allowed.