【发布时间】:2023-04-01 11:09:01
【问题描述】:
首先,我在带有最新 mingw 版本的 Windows 上使用代码块。我正在使用 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 -
std::tr1::function
会起作用吗? -
@PiotrS。然后它说tr1不是std的成员
-
@PiotrS。就这样做了,它奏效了!谢谢!
-
@PiotrS。实际上我刚刚意识到代码块没有采用我的 -std=c++11 选项!我必须手动选中一个框才能使用 c++11。现在我不需要 tr1。