c++ - 优先队列编译错误

标签 c++ compiler-errors priority-queue

我正在尝试编译下面的代码,但是编译器给出了错误

Struct.h:38:9: error: ‘priority_queue’ in namespace ‘std’ does not name a type

多次搜索都没有找到答案,所以我希望你们能帮忙。该代码部分基于 c++ 引用站点上提供的示例代码。

struct aimedShot;
union moveFunc;
struct timeCommand;

struct aimedShot
{
    void (*move) (Dot*, SDL_Event&, double x, double y);
    double x;
    double y;
};

//Holds the kind of function used
union moveFunc
{
    void (*notAimed) (Dot*);
    aimedShot aimed;
};

//Dot to be operated on and the appropriate operator with time
struct timeCommand
{
    Dot* target;    
    moveFunc command;
    int time;
    bool type; //True indicates aimed (integer inputs), False indicates unaimed
 }; 

class CompareCommand
{
     public:
     bool operator()(timeCommand& c1, timeCommand& c2) //Return true if c1 comes first
    {
        return (c1.time < c2.time);
    }
};

typedef std::priority_queue< timeCommand, std::vector<timeCommand>, CompareCommand> commandTimeline;

最佳答案

能够使用 std::priority_queue<> 您需要的类模板 #include <queue>标准标题。

关于c++ - 优先队列编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29069474/

相关文章:

c++ - 尝试访问 json 数据时获取 nullC++

c++ - rate++a,a++,a=a+1 和 a+=1 在 C 中的执行效率。假设 gcc 是编译器

c++ - 非静态函数可以修改c++中的静态变量吗

xcode "compile source as"覆盖特定文件

数组中的php函数

Java - 在比较器中进行排序以在优先级队列中使用

c++ - std::priority_queue<> 什么时候进行 self 排序?

algorithm - 什么时候对优先级队列使用堆是个坏主意?

c++ - binary_search 总是返回真 C++

java - 尝试创建新对象时出现不兼容类型错误