Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. I am not understanding why. " error: no match for 'operator=' (operand types are 'QVector<int>' and 'int') queue[rear++]=value; ^"
Forum Updated to NodeBB v4.3 + New Features

I am not understanding why. " error: no match for 'operator=' (operand types are 'QVector<int>' and 'int') queue[rear++]=value; ^"

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 4.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thippu
    wrote on 13 Jan 2019, 08:22 last edited by thippu
    #1

    I was practicing FIFO queue using QVector<int>* but I'm facing assignment error.
    In the enque() and line queue[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();
        }
    }
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 13 Jan 2019, 10:07 last edited by
      #2

      Hi
      You have a pointer to the queue.
      QVector<int> *queue=new QVector<int>; // points to it

      so 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

      T 1 Reply Last reply 13 Jan 2019, 10:20
      2
      • M mrjj
        13 Jan 2019, 10:07

        Hi
        You have a pointer to the queue.
        QVector<int> *queue=new QVector<int>; // points to it

        so 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

        T Offline
        T Offline
        thippu
        wrote on 13 Jan 2019, 10:20 last edited by
        #3

        @mrjj

        @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

        1 Reply Last reply
        0

        1/3

        13 Jan 2019, 08:22

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved