I am not understanding why. " error: no match for 'operator=' (operand types are 'QVector<int>' and 'int') queue[rear++]=value; ^"
-
I was practicing FIFO queue using
QVector<int>*
but I'm facing assignment error.
In theenque()
and linequeue[rear++]=value
.
I could not able to correct it, asking for help.
code :#define OPTION_LIMIT 4 #include <QCoreApplication> #include<QVector> #include<iostream> using namespace std; QVector<int> *queue=new QVector<int>; int size; int rear=-1; int front=-1; void enque() { if(rear>size-1) { display(); } else { if(front<0) { front=rear=0; } int value; cout<<"enter the content "<<endl; cin>>value; queue[rear++]=value; display(); } }
-
Hi
You have a pointer to the queue.
QVector<int> *queue=new QVector<int>; // points to itso you have to say
(*queue)[rear++]=value;
which really is
queue->operator=value;However, if you dont use pointer to queue
QVector<int> queue;
then
queue[rear++]=value; works.
Anyway, there is something else
on empty one will crash.
so make sure you have called append to add elements or use
http://doc.qt.io/qt-5/qvector.html#reserve
so make it a size to start with.
or change the logic to
//queue[rear++]=value;
queue .append(value);
rear++;Also Qt does have
http://doc.qt.io/qt-5/qqueue.html -
@mrjj said in I am not understanding why. " error: no match for 'operator=' (operand types are 'QVector<int>' and 'int') queue[rear++]=value; ^":
you have to say
(*queue)[rear++]=value;Thank you, bro build is fine now and I will make sure the queue is filled with zeros