错误:“int”不是类、结构或联合类型

error: ‘int’ is not a class, struct, or union type`

本文关键字:结构 类型 int 错误      更新时间:2023-10-16

我的代码出错。

vector<vector <int> > v;
deque <TreeNode, int> q;
pair <TreeNode, int> temp;//, node;
temp.first=*root, temp.second=0;
q.push_back(temp);   // error is in this line

TreeNode是一个定义为:

struct TreeNode {
    int val;
    TreeNode *left, *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

我在编译代码时遇到的错误是:/usr/include/c++/4.6/bits/stl_deque.h:487:61: error: ‘int’ is not a class, struct, or union type

在关注堆栈溢出的相关帖子后,我仍然不清楚。有人可以解释一下可能是什么原因吗?

vector<vector <int> > v;
deque <pair<TreeNode, int> > q; // here is the different
pair <TreeNode, int> temp;//, node;
temp.first=*root, temp.second=0;
q.push_back(temp);   // error is in this line

我想你想让树节点,int成对,

deque <pair<TreeNode, int> > q; // here is the different

然后添加到一个双端,

q.push_back(temp);   

你对q的声明是错误的。 通常,deque只需要一个模板参数 - 要存储在 deque 中的类型。 第二个参数(如果存在(是双端面的分配器类型。

根据这里,deque 的第二个模板参数应该是一个 Alloc 类。