Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

std

c++11

sfml

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?

like image 633
user3452725 Avatar asked Aug 31 '14 16:08

user3452725


1 Answers

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!

like image 74
user3452725 Avatar answered Sep 20 '22 12:09

user3452725