STL 算法函数名称解析

STL algorithm function name resolution

本文关键字:算法 函数 STL      更新时间:2023-10-16

我希望在下面的示例中,下面的编译器将无法编译代码,因为它不知道什么是"find()",它在算法标头的 std 命名空间中定义。

但是,此代码在带有 gcc 4.1.2 的 RHEL 5.3 上编译。

我错过了什么?

#include <string>    
#include <algorithm>
int main()
{
    std::string s;
    find(s.begin(), s.end(), 'a');  // should not compile
}

由于参数依赖查找,这有效。在参数类型的命名空间中搜索函数模板。在这种情况下,参数std::string::iterator,因此在命名空间std中搜索函数。