Can I return Null iterator from a function

£可爱£侵袭症+ 提交于 2020-02-14 02:28:30

问题


I'm porting some old code from vs6.0 to vs2015.

A function is returning a Null iterator; the caller compares it with NULL, which works in vs6.0, but in vs2015 that's an error. Is it possible that we can return a null iterator?

The old code looks something like this:

vector<string*>::iterator FindByCode()
{
   //some code
   if (itr == str.end) {
       return NULL;
   } else {
       return itr;
   }
}

int main()
{
    vector<string*>::iterator itr = FindByCode();
    if (itr == NULL) {
         return EXIT_FAILURE;
    }
}

来源:https://stackoverflow.com/questions/60033865/can-i-return-null-iterator-from-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!