0
// Implementing queue using array:
#include<bits/stdc++.h>
using namespace std;
class queue{
    public:
    int size;
    int f;
    int r;
    int *arr;
};
int isFull(queue *q)
{
    if(q->r==q->size-1)
    {
        return 1;
    }
    else{
        return 0;
    }
}
int enqueue(queue* q, int val){
    if(isFull(q))
    {
        cout<<"Overflow Condition";
    }
    else{
//      q->
cout<<"hi";
    }
}
int main()
{
    queue *q = new queue();
    q->f=q->r=-1;
    q->size=10;
    q->arr= new int[q->size];
    
    
}

I was trying to implement queue using array. But if I declare a class 'queue' it is showing error on the other hand when I used uppercase Q 'Queue' the program ran successfully. Can you explain why?

  • 2
    See [`std::queue`](https://en.cppreference.com/w/cpp/container/queue) – Some programmer dude Nov 07 '22 at 12:11
  • 3
    Also: [Why should I not #include ?](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) – Some programmer dude Nov 07 '22 at 12:11
  • Your `::queue` and C++ `std::queue` are colliding. Your `::Queue` doesn't collide because there is no `std::Queue`. – Eljay Nov 07 '22 at 12:19
  • `#include ` uses a non-standard header to get **all** of the names in the C++ standard library into your code. `using namespace std;` pulls all of those names into the global namespace, so you risk conflicts with every name in the C++ standard library. `queue` is only the first of many conflicts that you'll run into. – Pete Becker Nov 07 '22 at 17:11

0 Answers0