C++ 什么´;Qt中的这个模板有什么问题?QFile已删除构造函数?
这是我的模板函数。我得到了错误信息“调用'QFile'的已删除构造函数”。 我怎样才能解决这个问题?或者你能告诉我建议,我怎样才能以最好的方式编写这个函数作为模板C++ 什么´;Qt中的这个模板有什么问题?QFile已删除构造函数?,c++,qt,templates,methods,qfile,C++,Qt,Templates,Methods,Qfile,这是我的模板函数。我得到了错误信息“调用'QFile'的已删除构造函数”。 我怎样才能解决这个问题?或者你能告诉我建议,我怎样才能以最好的方式编写这个函数作为模板 template <class T> // T shall be the name of a class void example(QVector<T> &vec, const QString &fp, std::function<void(QFile)> func) //f
template <class T> // T shall be the name of a class
void example(QVector<T> &vec, const QString &fp, std::function<void(QFile)> func) //func is a method from a class
{
QFile f(fp);
if(!f.open(QIODevice::WriteOnly | QIODevice::Append) )
{
qDebug() << "File error" << f.error();
}
else
{
QThread::currentThread();
for(T &tw : vec)
{
//tw.func(f);
func(f).tw; **//call to deleted constructor of 'QFile'**
}
}
f.close();
}
template//T应为类的名称
void示例(QVector&vec,const QString&fp,std::function func)//func是类中的方法
{
qfilef(fp);
如果(!f.open(QIODevice::WriteOnly | QIODevice::Append))
{
qDebug()无法复制QFile
,因为复制构造函数已被删除。
将example
的签名改为使用std::function func
void writeTeamData(QFile&);
void teamType::writeTeams(QFile &f)
{
QTextStream out(&f);
out.setCodec("UTF-16LE");
out << teamId << "\t" << offsideTrap << "\t" << withoutBall << "\t" << formationId << "\t"
<< attack << "\t" << teamMentality << "\t" << attackTactic1 << "\t"
<< attackTactic2 << "\t" << defenseTactic1 << "\t" << defenseTactic2 << "\t" << captain << "\t"
<< penaltyTakerId << "\t" << kickTakerId << "\t" << leftCornerkickTakerId << "\t" << rightCornerkickTakerId << "\t"
<< numTransfersIn << endl;
}