【问题标题】:Mingw 'std::function' has not been declared?Mingw 'std::function' 没有被声明?
【发布时间】: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。

标签: c++ c++11 std sfml


【解决方案1】:

我想通了。 Piotr S 的一些功劳。我尝试了 std::tr1::function 但它本身不起作用,所以我只包含了 tr1/functional 并且它起作用了。谢谢!

【讨论】:

    猜你喜欢
    • 2017-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-10
    • 1970-01-01
    • 2021-01-02
    • 2018-06-05
    • 1970-01-01
    相关资源
    最近更新 更多