简体   繁体   中英

C++ iterator - strange conversion

I've encountered really strange error while working with iterators, and I am not really sure what to think about it: 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 is vector<TOwner*> (TOwner is 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();
};

ListCars returns a CCarList . You try to return 0, an int . There is no conversion from int to CCarList , so the attempt fails.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM