繁体   English   中英

C++ 没有 std:: 前缀或 using 语句的 endl()

[英]C++ endl() without std:: prefix or using statement

为什么在没有名称空间限定符的情况下使用endl()会编译? 我已经在多个编译器上尝试过,在这里搜索了几页搜索“endl without std::”,我很困惑为什么它甚至没有警告。

#include <iostream>

int main(){
    endl(std::cout << "hello weirdness");
    return 0;
}

这是从另一个网站上发现的一些故意混淆的代码中提炼出来的,我不会在真正的程序中使用它。 我只是不明白为什么它不抱怨没有定义endl

std::endl是一个 function 模板,具有以下签名:

template <class charT, class traits>
std::basic_ostream<charT, traits>& endl(std::basic_ostream<charT, traits>& os);

当参数的类型为std::ostream时,将进行参数相关查找,并在命名空间std中搜索名称 function endl

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM