Mingw报错:'std::function'未声明?

9

首先,我在Windows上使用最新的MinGW版本的Code Blocks。我正在使用SFML库启动游戏,但不幸的是,我遇到了这个问题。我需要使用std::function作为我的状态管理器,但它一直显示相同的错误:“未声明'std :: function'”。我尝试使用#include<functional>和链接器选项-std=c++0x,但仍然没有运气。唯一无法编译的是这个头文件:

#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

我不知道问题出在哪里。有人知道这里错了什么吗?


2
请使用--std=c++11代替过时的c++0x - Jarod42
std::tr1::function<State*()>会起作用吗? - Piotr Skotnicki
@PiotrS。然后它说tr1不是std的成员。 - user3452725
1
@PiotrS。刚刚试了一下,成功了!谢谢! - user3452725
2
@PiotrS,我刚刚意识到Codeblocks没有使用我的-std=c++11选项!我不得不手动勾选一个框来使用c++11。现在我不需要tr1了。 - user3452725
显示剩余4条评论
1个回答

5
我明白了。部分功劳归功于Piotr S. 我尝试了std::tr1::function,但它本身并不能正常工作,所以我只是包含了tr1/functional,并且它可以正常工作。谢谢!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接