4

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
  • 115,525
  • 42
  • 225
  • 281
zalyahya
  • 143
  • 1
  • 7
  • 17

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
  • 10,947
  • 13
  • 55
  • 86
  • 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
  • 97,027
  • 28
  • 181
  • 313
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,533
  • 3
  • 26
  • 50
  • 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