I'm trying to clean up my render loop and I thought this might work, since It works fine with a vector of Sprites/Shapes etc.:
std::vector< sf::drawable > Drawables;
Drawables.push_back(SomeSprite);
Drawables.push_back(SomeShape);
Drawables.push_back(SomeText);
...
for (unsigned int i = 0; i < Drawables.size(); i++)
{
App.Draw(Drawables[i]);
}
However the compilation fails with these errors:
/usr/include/c++/4.4/ext/new_allocator.h||In member function ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Tp*, const _Tp&) [with _Tp = sf::Drawable]’:|
/usr/include/c++/4.4/bits/stl_vector.h|737|instantiated from ‘void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = sf::Drawable, _Alloc = std::allocator<sf::Drawable>]’|
/home/jake/Projects/CodeBlocks workspaces/Meander/main.cpp|76|instantiated from here|
/usr/include/c++/4.4/ext/new_allocator.h|105|error: cannot allocate an object of abstract type ‘sf::Drawable’|
/usr/include/SFML/Graphics/Drawable.hpp|59|note: because the following virtual functions are pure within ‘sf::Drawable’:|
/usr/include/SFML/Graphics/Drawable.hpp|341|note: virtual void sf::Drawable::Render(sf::RenderTarget&) const|
/usr/include/c++/4.4/bits/vector.tcc||In member function ‘void std::vector<_Tp, _Alloc>::_M_insert_aux(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = sf::Drawable, _Alloc = std::allocator<sf::Drawable>]’:|
/usr/include/c++/4.4/bits/stl_vector.h|741|instantiated from ‘void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = sf::Drawable, _Alloc = std::allocator<sf::Drawable>]’|
/home/jake/Projects/CodeBlocks workspaces/Meander/main.cpp|76|instantiated from here|
/usr/include/c++/4.4/bits/vector.tcc|306|error: cannot allocate an object of abstract type ‘sf::Drawable’|
/usr/include/SFML/Graphics/Drawable.hpp|59|note: since type ‘sf::Drawable’ has pure virtual functions|
/usr/include/c++/4.4/bits/vector.tcc|306|error: cannot declare variable ‘__x_copy’ to be of abstract type ‘sf::Drawable’|
/usr/include/SFML/Graphics/Drawable.hpp|59|note: since type ‘sf::Drawable’ has pure virtual functions|
/usr/include/c++/4.4/bits/stl_uninitialized.h|117|instantiated from ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = sf::Drawable*, _ForwardIterator = sf::Drawable*]’|
/usr/include/c++/4.4/bits/stl_uninitialized.h|257|instantiated from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = sf::Drawable*, _ForwardIterator = sf::Drawable*, _Tp = sf::Drawable]’|
/usr/include/c++/4.4/bits/stl_uninitialized.h|267|instantiated from ‘_ForwardIterator std::__uninitialized_move_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = sf::Drawable*, _ForwardIterator = sf::Drawable*, _Allocator = std::allocator<sf::Drawable>]’|
/usr/include/c++/4.4/bits/vector.tcc|338|instantiated from ‘void std::vector<_Tp, _Alloc>::_M_insert_aux(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = sf::Drawable, _Alloc = std::allocator<sf::Drawable>]’|
/usr/include/c++/4.4/bits/stl_vector.h|741|instantiated from ‘void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = sf::Drawable, _Alloc = std::allocator<sf::Drawable>]’|
/home/jake/Projects/CodeBlocks workspaces/Meander/main.cpp|76|instantiated from here|
/usr/include/c++/4.4/bits/stl_uninitialized.h|74|error: cannot allocate an object of abstract type ‘sf::Drawable’|
/usr/include/SFML/Graphics/Drawable.hpp|59|note: since type ‘sf::Drawable’ has pure virtual functions|
which leads me to believe that a base class with pure virtual functions cannot be added to a vector. So:
Does anyone have a suggestion on how I would implement this?