简体   繁体   English

Mingw'std :: function'尚未声明?

[英]Mingw 'std::function' has not been declared?

First of all, I'm using code blocks on windows with the latest mingw release. 首先,我在具有最新mingw版本的Windows上使用代码块。 I am using the sfml library to start a game, but unfortunately I came across this problem. 我正在使用sfml库开始游戏,但不幸的是我遇到了这个问题。 I need to use std::function for my state manager, but it keeps showing the same error: 'std::function' has not been declared. 我需要为我的状态管理器使用std :: function,但是它一直显示相同的错误:尚未声明'std :: function'。 I did #include<functional> and used the linker option -std=c++0x, but still no luck. 我做了#include<functional>并使用了链接器选项-std = c ++ 0x,但还是没有运气。 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? 有人知道这里有什么问题吗?

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. 值得称赞的是PiotrS。我尝试了std :: tr1 :: function,但它本身无法正常工作,所以我只包含tr1 / functional,它就可以了。 Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM