我在几个地方看到过这个,为了确认我没有疯,我 looked for other examples .显然这也可以有其他形式,例如 operator+ <>
.
但是,我在任何地方都没有看到提到它是什么,所以我想我会问。
google operator<< <>(
不是最简单的事情:-)
最佳答案
<>
在声明中的函数名称(包括运算符,如 operator<<
)之后表示它是函数模板特化。例如,使用普通函数模板:
template <typename T>
void f(T x) { }
template<>
void f<>(int x) { } // specialization for T = int
(请注意,尖括号中可能列出了模板参数,具体取决于函数模板的特化方式)
<>
也可以在调用函数时在函数名后使用,以在存在通常在重载决策中更匹配的非模板函数时显式调用函数模板:
template <typename T>
void g(T x) { } // (1)
void g(int x) { } // (2)
g(42); // calls (2)
g<>(42); // calls (1)
所以,operator<< <>
不是运算符。
关于c++ - C++ 中的运算符 <<<> 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3011005/