我正在尝试在我的一个函数中使用 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/