Answer the question
In order to leave comments, you need to log in
Error: no matching constructor for initialization, what should I do?
There is a TemplateRequirement class, in another class, ReqTGroup, there is a vector whose elements are TemplateRequirement instances.
When I run it, it throws this error:
/Users/Mac/Qt/5.6/clang_64/lib/QtCore.framework/Headers/qvector.h:631: error: no matching constructor for initialization of 'TemplateRequirement'
T copy(t);
^ ~
As I understand it, the problem lies precisely in creating a vector, the elements of which are my class, but I can’t figure out how to fix it.
TemplateRequirement class:
class TemplateRequirement
{
public:
TemplateRequirement();
TemplateRequirement(TemplateRequirement &);
TemplateRequirement(QString&,QString&, QString&);
TemplateRequirement& operator=(TemplateRequirement&);
QString getReq();
QString getType();
QString getHead();
void save(std::ofstream &);
void read(std::ifstream &);
void setRequirement(QString&);
protected:
QString head;
QString requirement;
QString type;
};
class ReqTGroup
{
public:
ReqTGroup();
ReqTGroup (int);
void save();
void read();
int findByHead(QString&);
void addItrm(QString, QString, QString);
protected:
QVector<TemplateRequirement> requirements;
};
Answer the question
In order to leave comments, you need to log in
Incorrectly declared copy constructor and assignment operator:
TemplateRequirement(TemplateRequirement &);
TemplateRequirement& operator=(TemplateRequirement&);
TemplateRequirement(const TemplateRequirement &);
TemplateRequirement& operator=(const TemplateRequirement&);
QString
and QString&
with const QString&
.
Maybe the const is missing in the copy constructor .TemplateRequirement(const TemplateRequirement &);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question