【发布时间】:2014-09-26 08:52:08
【问题描述】:
在某些情况下,我似乎可以访问应该在 std 命名空间中没有 using 或 std:: 限定符的函数。到目前为止,我只看到 algorithm 库中的函数会出现这种情况。
在以下示例中,我希望 all_of() 位于 std 命名空间中,但此代码在 VS2013(Microsoft 编译器 18)中编译没有错误。
#include <iostream>
#include <string>
#include <algorithm>
int main() {
const std::string text = "hey";
std::cout << all_of(begin(text),end(text),islower);
return 0;
}
将std::cout 更改为cout 而不添加using namespace std 或using std::cout 会按预期生成“未声明的标识符”错误。
这是怎么回事?
【问题讨论】:
-
依赖于参数的查找?
-
@Niall 并不是真的重复,我会说。
std::string::const_iterator是命名空间std中的一个类并不是很明显。 -
Google 搜索“命名空间 std cout 查找”无论如何都会产生 ADL
-
@Marco-A 好吧,但我不知道使用关键字“查找”。 ;)
标签: c++ algorithm include std using