将 STL 队列与自定义数据结构结合使用
Using STL queue with custom data structure
我正在尝试在我的一个函数中使用 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 个错误都会消失。
尝试在命名空间中定义函数外部的结构,例如在全局命名空间中。似乎你有一个旧的编译器。
相关文章:
- 链表,反向函数,数据结构
- 如何使用set实现无序数据结构?
- 我们可以将数据永久保存为数据结构吗?
- C++中的可变长度数组/数据结构
- 用于存储由空格分隔的字符串的 C++/C 数据结构
- 通过 NIF 从C++返回自定义数据结构
- 编译器上的策略数据结构不起作用
- 尝试构建"lock-free"数据结构C++
- 设计将引用元素移动到开头的数据结构.C++
- 在学习数据结构之前对STL有一个了解是好的吗?
- 如何解析表示树状数据结构的字符串
- 我对数据结构、双向链表有一些问题
- googletest:测试太大的数据结构
- C++中deque数据结构的大O是什么?
- 我可以使用哪种数据结构来处理这种方式
- 将文本文件解析为树状数据结构
- C++ 中具有 O(1) 搜索时间复杂度的数据结构
- 哪些存储了不完整类型的 STL 数据结构可以用作类成员?
- 将'std::cin'与数据结构成员结合使用
- 将 STL 队列与自定义数据结构结合使用