Mingw 'std::function' has not been declared?

user3452725 picture user3452725 · Aug 31, 2014 · Viewed 8.6k times · Source

First of all, I'm using code blocks on windows with the latest mingw release. I am using the sfml library to start a game, but unfortunately I came across this problem. I need to use std::function for my state manager, but it keeps showing the same error: 'std::function' has not been declared. I did #include<functional> and used the linker option -std=c++0x, but still no luck. The only thing that doesn't compile is this one header:

#ifndef STATEMANAGER_HPP_INCLUDED
#define STATEMANAGER_HPP_INCLUDED

#include <vector>
#include "State.hpp"
#include <functional>
#include <SFML/Graphics.hpp>

class StateManager {
public:
    StateManager();
    ~StateManager();

    void registerState(int id, std::function< State*() > createFunc);

    void setState(int id);

    void update();

    void draw(sf::RenderTarget &target);
private:
    std::vector< std::function< State*() > > mStates;
    State *mCurrentState;
};

#endif // STATEMANAGER_HPP_INCLUDED

I have no idea what the problem is. Anyone know whats wrong here?

Answer

user3452725 picture user3452725 · Aug 31, 2014

I figured it out. Some credit to Piotr S. I tried std::tr1::function but that didn't work on its own, so i just included tr1/functional and it worked. Thanks!