c ++ find命令不再有效

时间:2016-06-09 15:04:31

标签: c++ list iterator find

这是一些不是我写的旧代码。它用GCC 3.4.6编译,但现在我们用GCC 4.4.7检查构建,并且构建失败。

我希望这段代码能够继续下去:

list<Chapter*>  * tocP;   //Chapter is a class

tocP = NULL;
if (_searchChapter)
{
_chapter = _manager->GetCurrentChapter();   // _chapter is a Chapter*
}
else
{
tocP = _manager->GetTableOfContents();

if (tocP != NULL && tocP->size() > 0)
    _chapter = tocP->front();
}
...

list<Chapter*>::iterator chp;

if (tocP != NULL && tocP->size() > 0)
for (chp=find(tocP->begin(),tocP->end(),_chapter); chp != tocP->end(); ++chp)  // this code fails
{
   //code to process chapter
}

错误信息是:

../ src / HelpSearchC.C:在成员函数&#39; int HelpSearchC_i :: DoSearch()&#39;: ../src/HelpSearchC.C:685:错误:没有匹配函数来调用&#39; find(std :: _ List_iterator&lt; Chapter *&gt;, std :: _ List_iterator&lt; Chapter *&gt ;, Chapter *&amp;)&#39;

1 个答案:

答案 0 :(得分:1)

您必须在文件顶部添加#include <algorithm>。函数find在此标题中定义。

相关问题