I have a function in my main class in my Snake Game SnakeGame::getDrawables which returns a std::vector<sf::Drawable*> which contains all of my drawable objects. However, the function body for this function is not working for me, which is as follows:
(All of these objects are derived from the base class sf::Drawable.) I feel like I am missing a basic concept, but do not know what it is:
Here is the error message I am getting, on Visual Studio Community 2017 edition:
Severity Code Description Project File Line Suppression State
Error (active) E0304 no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=sf::Drawable *, _Alloc=std::allocator<sf::Drawable *>]" matches the argument list SnakeGame c:\Users\arnav_1n7er7u\Documents\Visual Studio 2017\Projects\SnakeGame\SnakeGame\SnakeGame.cpp 84
Since the function getDrawables() is const the members gameMap_ etc. are const as well. So either you remove the const from the function or you return const sf::Drawable*. If the latter works it would be preferable due to the const correctness: