Почему вылетает ошибка: C:\DEVELOPMENT\Qt5.12.9\5.12.9\mingw73_64\include\QtCore\qvector.h:687: ошибка: cannot bind non-const lvalue reference of type 'AltIdent&' to an rvalue of type 'std::remove_ref
Всем доброго времени суток.
Помогите разобраться, что я делаю не так?
Есть несколько классов. Вот они:
class AltIdent { public: AltIdent(); AltIdent(const AltIdent &); AltIdent(PartNumber partnumber, ManufacturerCode manufacturercode); ~AltIdent(){} PartNumber getPartNumberObject() const; void setPartNumberObject(const PartNumber &value); ManufacturerCode getManufacturerCodeObject() const; void setManufacturerCodeObject(const ManufacturerCode &value); bool isEmpty(); AltIdent *isNull(); AltIdent operator= (AltIdent &altident); private: PartNumber partNumberObject; ManufacturerCode manufacturerCodeObject; }; #include "altident.h" AltIdent::AltIdent() { } AltIdent::AltIdent(const AltIdent &altident) { partNumberObject = altident.getPartNumberObject(); manufacturerCodeObject = altident.getManufacturerCodeObject(); } AltIdent::AltIdent(PartNumber partnumnber, ManufacturerCode manufacturercode): partNumberObject(partnumnber), manufacturerCodeObject(manufacturercode) { } PartNumber AltIdent::getPartNumberObject() const { return partNumberObject; } void AltIdent::setPartNumberObject(const PartNumber &value) { partNumberObject = value; } ManufacturerCode AltIdent::getManufacturerCodeObject() const { return manufacturerCodeObject; } void AltIdent::setManufacturerCodeObject(const ManufacturerCode &value) { manufacturerCodeObject = value; } bool AltIdent::isEmpty() { if(isNull() != nullptr){ if(!getPartNumberObject().isEmpty()){ return false; } if(!getManufacturerCodeObject().isEmpty()){ return false; } } return true; } AltIdent *AltIdent::isNull() { AltIdent *altIdent = this; if(altIdent != nullptr){ return this; } return nullptr; } AltIdent AltIdent::operator=(AltIdent &altident) { return *new AltIdent(altident.getPartNumberObject(), altident.getManufacturerCodeObject()); }
class PartNumber { public: PartNumber(); PartNumber(const PartNumber &); PartNumber(const QString &partNumberStr, const QMap<QString, QString> &attrMap); ~PartNumber(){} QString getPartNumberValue() const; void setPartNumberValue(const QString &value); QMap<QString, QString> getPartNumberAttrMap() const; void setPartNumberAttrMap(const QMap<QString, QString> &value); bool isEmpty(); PartNumber *isNull(); private: QString partNumberValue; QMap<QString, QString> partNumberAttrMap; }; #include "partnumber.h" PartNumber::PartNumber() { } PartNumber::PartNumber(const PartNumber &partnumber) { partNumberValue = partnumber.getPartNumberValue(); partNumberAttrMap = partnumber.getPartNumberAttrMap(); } PartNumber::PartNumber(const QString &partNumberStr, const QMap<QString, QString> &attrMap) : partNumberValue(partNumberStr), partNumberAttrMap(attrMap) { } QMap<QString, QString> PartNumber::getPartNumberAttrMap() const { return partNumberAttrMap; } void PartNumber::setPartNumberAttrMap(const QMap<QString, QString> &value) { partNumberAttrMap = value; } QString PartNumber::getPartNumberValue() const { return partNumberValue; } void PartNumber::setPartNumberValue(const QString &value) { partNumberValue = value; } bool PartNumber::isEmpty() { if(isNull() != nullptr && !partNumberValue.isEmpty()){ return false; } return true; } PartNumber *PartNumber::isNull() { PartNumber *partNumber = this; if(partNumber != nullptr){ return this; } return nullptr; }
class ManufacturerCode { public: ManufacturerCode(); ManufacturerCode(const ManufacturerCode &); ManufacturerCode(const QString &manufacturerCode, const QMap<QString, QString> &attrMap); ~ManufacturerCode(){} QMap<QString, QString> getManufacturerCodeAttrMap() const; void setManufacturerCodeAttrMap(const QMap<QString, QString> &value); QString getManufacturerCodeValue() const; void setManufacturerCodeValue(const QString &value); QDomElement manufacturerCodeToXml(QDomDocument &domdocument); void manufacturerCodeFromXml(QDomElement &domelement); bool isEmpty(); ManufacturerCode *isNull(); private: QString manufacturerCodeValue; QMap<QString, QString> manufacturerCodeAttrMap; }; #include "manufacturercode.h" ManufacturerCode::ManufacturerCode() { } ManufacturerCode::ManufacturerCode(const ManufacturerCode &manufacturercode) { *this = manufacturercode; } ManufacturerCode::ManufacturerCode(const QString &manufacturerCode,const QMap<QString, QString> &attrMap) : manufacturerCodeValue(manufacturerCode), manufacturerCodeAttrMap(attrMap) { } QMap<QString, QString> ManufacturerCode::getManufacturerCodeAttrMap() const { return manufacturerCodeAttrMap; } void ManufacturerCode::setManufacturerCodeAttrMap(const QMap<QString, QString> &value) { manufacturerCodeAttrMap = value; } QString ManufacturerCode::getManufacturerCodeValue() const { return manufacturerCodeValue; } void ManufacturerCode::setManufacturerCodeValue(const QString &value) { manufacturerCodeValue = value; } bool ManufacturerCode::isEmpty() { if(isNull() != nullptr && !manufacturerCodeValue.isEmpty()){ return false; } return true; } ManufacturerCode *ManufacturerCode::isNull() { ManufacturerCode *manufacturerCode = this; if(manufacturerCode != nullptr){ return this; } return nullptr; }
В другом файле сосздаю вектор:
AltIdent m_altIdentOrigin; AltIdent m_altIdentCurrent; QVector<AltIdent> m_altIdentList;
На кнопку QPushButton повесил обработчик, который должен по индексу присвоить переменной m_altIdentCurrent элемент массива
void AltIdentGroupWidget::previewItem(const int &index) { m_altIdentOrigin = m_altIdentList.at(index); }
Но при компиляции получаю следующие ошибки:
1. C:\DEVELOPMENT\Qt5.12.9\5.12.9\mingw73_64\include\QtCore\qvector.h:687: ошибка: cannot bind non-const lvalue reference of type 'AltIdent&' to an rvalue of type 'std::remove_reference
d->end() = qMove(copy);
2. C:\DEVELOPMENT\Qt5.12.9\5.12.9\mingw73_64\include\QtCore\qvector.h:693: ошибка: binding reference of type 'AltIdent&' to 'const AltIdent' discards qualifiers
d->end() = t;
~~~~~~~~~~^~~
И я не могу разобраться, что я делаю не так?
Помогите разобраться, пожалуйста.
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.Do you like it? Share on social networks!
- Akiv Doros
- Nov. 11, 2024, 10:58 p.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:50points,
- Rating points-4
- molni99
- Oct. 26, 2024, 8:37 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:80points,
- Rating points4
- molni99
- Oct. 26, 2024, 8:29 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:20points,
- Rating points-10
Еще у меня вопрос. Правильно ли я написал конструктор копирования и перегрузил операцию присваивания?