QVector <QVector int >> change "inside" vector
I have the following variable in QT:
QVector<QVector <int> > buff_d1;
and I need to change the "inner" vector:
buff_d1.at(i).removeFirst();
buff_d1.at(i).push_back(d1.at(i).at(sample_number));
this throws errors:
passing 'const QVector<int>' as 'this' argument of 'void QVector<T>::removeFirst() [with T = int]' discards qualifiers [-fpermissive] buff_d2.at(i).removeFirst();
passing 'const QVector<int>' as 'this' argument of 'void QVector<T>::push_back(const T&) [with T = int]' discards qualifiers [-fpermissive] buff_d1.at(i).push_back(d1.at(i).at(sample_number));
I understand that the "internal" vector is const, so I cannot change it, but what is the job?
+3
source to share
2 answers
The at () function returns a reference const
:
const T & QVector::at(int i) const
and you are trying to change that with the removeFirst () function . You must use the [] operator to change it as it provides a non-const return overload:
T & QVector::operator[](int i)
The same goes for the second error.
+4
source to share