5

I'm trying to declare a queue in c++:

#include <queue>
......
......
queue<Process> *readyQueue = new queue<Process>;
.......

But i keep getting this error

'queue' was not declared in this scope

What am I missing? I, of course, created the Process struct, so the problem isn't there. What's the issue?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
zalyahya
  • 153
  • 1
  • 7
  • 18

3 Answers3

19

You are missing namespace specification. I suppose you want std functions. Use either:

 #include <queue>
 ......
 std::queue<Process> *readyQueue = new std::queue<Process>;

or

 #include <queue>
 using std::queue;
 ......
 queue<Process> *readyQueue = new queue<Process>;
klm123
  • 12,105
  • 14
  • 57
  • 95
  • 4
    Can whoever downvoted this answer comment on the reason for the downvote? Given that the fix is the correct fix, it is entirely unwarranted. – Dietmar Kühl Nov 03 '13 at 15:44
8

You need to specify the correct namespace

std::queue

John Dibling
  • 99,718
  • 31
  • 186
  • 324
7

You should use using namespace std; or the std:: prefix. This might help you:

#include <queue>

int main()
{
    Process p1;
    Process p2;

    std::queue<Process> readyQueue;
    readyQueue.push(p1);
    readyQueue.push(p2);
}

See reference for more details.

Netherwire
  • 2,669
  • 3
  • 31
  • 54
  • 1
    [`using namespace std`](http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) is not so cool. Other than that the answer is completely correct. – juanchopanza Nov 03 '13 at 15:46
  • @juanchopanza, you're right. Just an another option. In ordinary, i'm trying to avoid this at all and use std:: prefix. – Netherwire Nov 03 '13 at 17:23