Coder
Coder

Reputation: 1899

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

I am getting error for my code.

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 is a structure defined as:

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

The error I am getting on compiling the code is: /usr/include/c++/4.6/bits/stl_deque.h:487:61: error: ‘int’ is not a class, struct, or union type

I am still unclear after following related posts on stackoverflow. Can someone please explain what could be the reason?

Upvotes: 3

Views: 14401

Answers (3)

KunMing Xie
KunMing Xie

Reputation: 1667

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

i think you want to make TreeNode, int as pair,

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

then add to a deque,

q.push_back(temp);   

Upvotes: 5

Xiaotian Pei
Xiaotian Pei

Reputation: 3260

According to here, the second template argument of deque should be an Alloc class.

Upvotes: 2

1201ProgramAlarm
1201ProgramAlarm

Reputation: 32732

Your declaration of q is wrong. Normally a deque will only require one template argument - the type to store in the deque. The second parameter, if present, is an allocator type for the deque.

Upvotes: 3

Related Questions