2016-06-09 90 views
-1

这不是我写的一些旧的代码。它使用GCC 3.4.6进行编译,但现在我们正在使用GCC 4.4.7检查构建,并且构建失败。C++ find命令不再起作用

我希望这个代码是足够去:

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:在成员函数 '廉政HelpSearchC_i :: DoSearch()' : ../src/HelpSearchC.C:685:错误:没有匹配函数调用 '找到(STD :: _ List_iterator <章* >, 的std :: _ List_iterator <章* >,章* &)'

+4

你有没有'#包括'? – lllllllllll

+0

那么这是肯定快!非常感谢。问题没有了。 – geoffw35

+0

因此,GCC 3.4.6只是在找到算法的定义时不需要#include ? – geoffw35

回答

1

您必须在文件顶部添加#include <algorithm>。功能find在此标题内定义。