我一直试图<<为我的列表重载运算符,但我无法输出它。我有以下错误,我不知道如何解决它:
错误:'std::cout << *it (std::_List_const_iterator<_Tp>::operator* with _Tp = Joc)' 中的 'operator<<' 不匹配
这些是我试图重载<<运算符的方法,但它们都不能使用迭代器输出我的列表。我不知道如何解决它。
ostream& Joc::afisare(ostream &os) const
{
os << endl;
os << "Numele jocului:" << this->nume << ' ' << "Stoc:" << this->stoc << ' ' << "Descrierea joc: " << this->Descriere << ' ';
for(list<string>::const_iterator it = upd.begin(); it != upd.end(); it++)
{
os << "Lista:" << *it << endl;
}
os << endl;
return os;
}
ostream& operator<<(ostream &os, Joc &j)
{
return j.afisare(os);
}
void Joc::afisare() const
{
cout << "Numele jocului:" << this->nume << ' ' << "Stoc:" << this->stoc << ' ' << "Descrierea joc: " << this->Descriere << ' ';
for(list<string>::const_iterator it = upd.begin(); it != upd.end(); it++)
{
cout << "Lista:" << *it << endl;
}
}
主要的:
list<Joc> jx;
jx.push_back(j6);
jx.push_back(j7);
for(list<Joc>::const_iterator it = jx.begin(); it != jx.end(); it++)
{
cout << *it;
}
我尝试使用cout << it->afisare();,但它仍然没有工作。我不知道该怎么办。
我认为问题出在<<操作员上,但我不知道如何解决。