将 STL 队列与自定义数据结构结合使用

Using STL queue with custom data structure

本文关键字:结合 数据结构 自定义 STL 队列      更新时间:2023-10-16

我正在尝试在我的一个函数中使用 STL 队列。在函数内部,我有以下代码:

struct node {
    int player1X, player1Y, player2X, player2Y;
    int steps;
};
queue<node> q;

但不知何故,这个队列不会初始化错误(queue<int>工作正常(。我做错了什么?

PS 带有声明的行上有 4 个错误:

error: template argument for ‘template<class> class std::allocator’ uses local type ‘PathFinding::minTurns(std::vector<std::basic_string<char> >)::node’
error:   trying to instantiate ‘template<class> class std::allocator’
error: template argument 2 is invalid
error: invalid type in declaration before ‘;’ token

如果我将node交换给int,所有 4 个错误都会消失。

尝试在命名空间中定义函数外部的结构,例如在全局命名空间中。似乎你有一个旧的编译器。