亲爱的stackoverflow社区,我对如何让qlistiterator在qlist上运行有疑问。根据 qt 的文档,qlistiterator 有一个赋值运算符 "=",如下所示:
QListIterator & QListIterator::operator=(const QList<T> & list)
对于我的代码,我的主窗口类中有两个成员:
QList<int> timepoints;
QListIterator<int> timeIter(QList<int> &list);
在构造函数中:
timeIter=timepoints;
但是这一行给出了一个错误:
invalid use of member function (did you forget the '()' ?)
任何人都可以帮助解释为什么?
QListIterator被错误地声明为成员函数而不是成员变量。
在类声明中使用:
class YourClass {
QListIterator<int> timeIter;
};
赋值运算符允许您重新赋值迭代器。它不能按预期使用,因为QListIterator
没有默认构造函数。因此,若要执行要执行的操作,请使用初始值设定项:
YourClass::YourClass()
:timeIter{timepoints}
{
}