SFML community forums

Help => General => Topic started by: flashrocket on April 14, 2015, 10:55:53 am

Title: error: ‘begin’ was not declared in this scope in vertexarray
Post by: flashrocket on April 14, 2015, 10:55:53 am
Im learning c++ 11 and i found this error
#include<SFML/Graphics.hpp>

int main()
{
        sf::VertexArray a;
        for(auto& b:a)
        {
       
        }
}
 
error when compiled with GCC
Code: [Select]
g++ test.cpp -o test -lsfml-graphics -lsfml-window -lsfml-system -std=c++11
test.cpp: In function ‘int main()’:
test.cpp:6:14: error: ‘begin’ was not declared in this scope
  for(auto& b:a)
              ^
test.cpp:6:14: note: suggested alternative:
In file included from /usr/include/c++/4.9/bits/basic_string.h:42:0,
                 from /usr/include/c++/4.9/string:52,
                 from /usr/include/c++/4.9/bits/locale_classes.h:40,
                 from /usr/include/c++/4.9/bits/ios_base.h:41,
                 from /usr/include/c++/4.9/ios:42,
                 from /usr/include/c++/4.9/ostream:38,
                 from /usr/include/SFML/System/Err.hpp:32,
                 from /usr/include/SFML/System.hpp:34,
                 from /usr/include/SFML/Window.hpp:32,
                 from /usr/include/SFML/Graphics.hpp:32,
                 from test.cpp:1:
/usr/include/c++/4.9/initializer_list:89:5: note:   ‘std::begin’
     begin(initializer_list<_Tp> __ils) noexcept
     ^
test.cpp:6:14: error: ‘end’ was not declared in this scope
  for(auto& b:a)
              ^
test.cpp:6:14: note: suggested alternative:
In file included from /usr/include/c++/4.9/bits/basic_string.h:42:0,
                 from /usr/include/c++/4.9/string:52,
                 from /usr/include/c++/4.9/bits/locale_classes.h:40,
                 from /usr/include/c++/4.9/bits/ios_base.h:41,
                 from /usr/include/c++/4.9/ios:42,
                 from /usr/include/c++/4.9/ostream:38,
                 from /usr/include/SFML/System/Err.hpp:32,
                 from /usr/include/SFML/System.hpp:34,
                 from /usr/include/SFML/Window.hpp:32,
                 from /usr/include/SFML/Graphics.hpp:32,
                 from test.cpp:1:
/usr/include/c++/4.9/initializer_list:99:5: note:   ‘std::end’
     end(initializer_list<_Tp> __ils) noexcept
     ^

error when compiled with clang
Code: [Select]
clang++ test.cpp -o test -lsfml-graphics -lsfml-window -lsfml-system -std=c++11
test.cpp:6:13: error: invalid range expression of type 'sf::VertexArray'; no
      viable 'begin' function available
        for(auto& b:a)
                   ^~
1 error generated.
Title: AW: error: ‘begin’ was not declared in this scope in vertexarray
Post by: eXpl0it3r on April 14, 2015, 11:02:04 am
It's not an error. VertexArray has not been designed as a standard container.
At best you use std::vector<sf::Vertex> directly, since VertexArray is nothing else but a thin wrapper around it.
Otherwise you can still declare begin() and end() for the VertexArray as free functions.
Title: Re: error: ‘begin’ was not declared in this scope in vertexarray
Post by: flashrocket on April 14, 2015, 11:06:40 am
Thank you for the quick answer. :) :)