以下函数模板中第二个括号<>的原因是什么:
template<> void doh::operator()<>(int i)
Run Code Online (Sandbox Code Playgroud)
这出现在SO问题中,有人提出之后有一些括号丢失operator(),但是我找不到解释.
如果它是表单的类型特化(完全特化),我理解其含义:
template< typename A > struct AA {};
template<> struct AA<int> {}; // hope this is correct, specialize for int
Run Code Online (Sandbox Code Playgroud)
但是对于功能模板:
template< typename A > void f( A );
template< typename A > void f( A* ); // overload of the above for pointers
template<> void f<int>(int); // full specialization for int
Run Code Online (Sandbox Code Playgroud)
这适合这种情况?:
template<> void doh::operator()<>(bool b) {}
Run Code Online (Sandbox Code Playgroud)
示例代码似乎有效并且没有给出任何警告/错误(使用gcc 3.3.3):
#include <iostream>
using namespace std;
struct doh
{
void operator()(bool …Run Code Online (Sandbox Code Playgroud)