1
When compiling I get the following error, in Qlist. I’m using Qt 5.6.
error: use of Deleted Function 'Vitamin::Vitamin(const Vitamin&)' Current->v = new T(*reinterpret_cast(src->v));
error: use of Deleted Function 'Vitamin::Vitamin(const Vitamin&)' new (Current) T(*reinterpret_cast(src));
error: use of Deleted Function 'Vitamin::Vitamin(const Vitamin&)' Else if (Qtypeinfo::isComplex) new (n) T(t);
error: use of Deleted Function 'Vitamin& Vitamin::Operator=(const Vitamin&)' Else *reinterpret_cast(n) = t;
Base Class
Header
#ifndef COMPONETNUTRITIONAL
#define COMPONETNUTRITIONAL
#include <QObject>
#include <QList>
class ComponentNutritional:public QObject
{
Q_OBJECT
public:
explicit ComponentNutritional(QObject *parent = 0);
~ComponentNutritional();
QString getName();
float getValue();
float getDairyValue();
QString getMeasure();
protected:
QString name;
float value;
float dairyvalue;
QString measure;
};
#endif // COMPONETNUTRITIONAL
Cpp
#include "componetnutritional.h"
#include <typeinfo>
ComponentNutritional::ComponentNutritional(QObject *parent):QObject(parent)
{
this->name = typeid(this).name();
this->dairyvalue = 0;
this->measure = "";
this->value = 0;
}
ComponentNutritional::~ComponentNutritional()
{
}
QString ComponentNutritional::getName()
{
return this->name;
}
float ComponentNutritional::getValue()
{
return this->value;
}
float ComponentNutritional::getDairyValue()
{
return this->dairyvalue;
}
QString ComponentNutritional::getMeasure()
{
return this->measure;
}
Class that achieves inheritance
Header
#ifndef VITAMIN_H
#define VITAMIN_H
#include <QObject>
#include "Library/Types/Base/componetnutritional.h"
class Vitamin : public ComponentNutritional
{
public:
explicit Vitamin(QObject *parent = 0);
~Vitamin();
Q_INVOKABLE Vitamin *setName(QString value);
Q_INVOKABLE Vitamin *setValue(float value);
Q_INVOKABLE Vitamin *setDairyValue(float value);
Q_INVOKABLE Vitamin *setMeasure(QString value);
};
class Vitamins: public QList<Vitamin>{
};
#endif // VITAMIN_H
Cpp
#include "vitamin.h"
Vitamin::Vitamin(QObject *parent): ComponentNutritional(parent)
{
}
Vitamin::~Vitamin()
{
}
Vitamin *Vitamin::setName(QString value)
{
this->name = value;
return this;
}
Vitamin *Vitamin::setValue(float value)
{
this->value = value;
return this;
}
Vitamin *Vitamin::setDairyValue(float value)
{
this->dairyvalue = value;
return this;
}
Vitamin *Vitamin::setMeasure(QString value)
{
this->measure = value;
return this;
}
Solution
#ifndef VITAMIN_H
#define VITAMIN_H
#include <QObject>
#include "Library/Types/Base/componetnutritional.h"
class Vitamin : public ComponentNutritional
{
public:
explicit Vitamin(QObject *parent = 0);
~Vitamin();
Q_INVOKABLE Vitamin *setName(QString value);
Q_INVOKABLE Vitamin *setValue(float value);
Q_INVOKABLE Vitamin *setDairyValue(float value);
Q_INVOKABLE Vitamin *setMeasure(QString value);
};
class Vitamins: public QList<Vitamin*>{ //Alterado para ponteiro
};
#endif // VITAMIN_H
Man, you could wipe that question down and leave just a minimal example, but demonstrate your problem.
– Romário