C ++迭代器 - 奇怪的转换

时间:2015-03-24 23:03:19

标签: c++ vector iterator

我在使用迭代器时遇到了非常奇怪的错误,我不确定该怎么想: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_ownersvector<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();
};

1 个答案:

答案 0 :(得分:6)

ListCars返回CCarList。您尝试返回0,int。没有从intCCarList的转换,因此尝试失败。