ahm*_*eek 1 c++ manipulators c++11
我想知道:例如,如果std::endl是常规函数,那为什么它缺少调用运算符(the operator())?
我知道它被设计为与insertion(<<)和extraction(>>)运算符一起使用.我试着像这样称呼它:
std::endl.();
但当然这不起作用.
std::endl只是一个可以调用的普通函数(或者更确切地说是函数模板).你只需要用正确的参数调用它:
std::endl(std::cout);    // OK, equivalent to "std::cout << std::endl;"
那是因为ostream函数指针的移位运算符重载,其方式等同于:
ostream & operator<<(ostream & os, ostream & (*f)(ostream &))
{
    return f(os);
}
(它实际上是basic_ostream处理任何类型的角色特征和分配器的模板.)