我在使用迭代器时遇到了非常奇怪的错误,我不确定该怎么想:error: could not convert ‘0’ from ‘int’ to ‘CCarList’
CCarList CRegister::ListCars(const string& name, const string& surname) const {
auto ownerIt = findOwner(name, surname);
if (ownerIt == m_owners.end()) return 0; //Error is on this line
//...
}
findOwner:
vector<TOwner*>::const_iterator CRegister::findOwner(const string& name,
const string& surname) const
{
return lower_bound(m_owners.begin(), m_owners.end(), TOwner(name, surname),
[](const TOwner* a, const TOwner& b){return (*a) < b;});
}
m_owners
是vector<TOwner*>
(TOwner是struct。)
CCarList:
class CCarList {
vector<TCar*>::iterator m_it;
const vector<TCar*>::iterator m_end;
public:
CCarList(vector<TCar*>::iterator it, const vector<TCar*>::iterator end):
m_it(it), m_end(end){}
CCarList(){}
string RZ() const;
bool AtEnd() const;
void Next();
};
答案 0 :(得分:6)
ListCars
返回CCarList
。您尝试返回0,int
。没有从int
到CCarList
的转换,因此尝试失败。