c++ - 使用具有自定义数据结构的 STL 队列

标签 c++ stl queue

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

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

但是不知何故这个队列不会初始化 witout 错误(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,所有 4 个错误都会消失至 int .

最佳答案

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

关于c++ - 使用具有自定义数据结构的 STL 队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27623387/

相关文章:

c++ - 如何使用 Boost 在 C++ 中制作代理服务器

c++ - 按某个数据成员对结构的 STL 容器进行排序

c++ - 如何在 CppUnit 中漂亮地打印 STL 数据结构?

javascript - 队列.js : difference between array of functions & array of closures?

java - 打印优先队列的内容

c++ - 如果某些成员变量在构造函数中初始化,则析构函数中出现神秘的 SIGABRT

c++ - 二项式堆 - 实现运行速度太慢

python - 将脚本语言嵌入到游戏引擎的编程语言中的目的是什么?

c++ - OpenGL 和 STL?

.net - .NET 中队列 <T> 的大小限制?