首先,我在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
我不知道问题出在哪里。有人知道这里错了什么吗?
--std=c++11
代替过时的c++0x
。 - Jarod42