Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: error: ‘begin’ was not declared in this scope in vertexarray  (Read 10510 times)

0 Members and 1 Guest are viewing this topic.

flashrocket

  • Newbie
  • *
  • Posts: 21
    • View Profile
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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
AW: error: ‘begin’ was not declared in this scope in vertexarray
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

flashrocket

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: error: ‘begin’ was not declared in this scope in vertexarray
« Reply #2 on: April 14, 2015, 11:06:40 am »
Thank you for the quick answer. :) :)