>次の関数テンプレートで:関数テンプレート特殊フォーマット第二ブラケット<理由は何
template<> void doh::operator()<>(int i)
これは、それが私ができるしかし、operator()
後に行方不明括弧があることが示唆されたSO questionに思い付い説明を見つけられません。
それはフォームのタイプ専門(フル分業)だった場合、私は意味を理解する:
関数テンプレートのためしかしtemplate< typename A > struct AA {};
template<> struct AA<int> {}; // hope this is correct, specialize for int
:
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
がこのscenarionに収まらない場合は?:
template<> void doh::operator()<>(bool b) {}
動作していると思われるコード例はありませんrnings /エラー(使用のgcc 3.3.3):
#include <iostream>
using namespace std;
struct doh
{
void operator()(bool b)
{
cout << "operator()(bool b)" << endl;
}
template< typename T > void operator()(T t)
{
cout << "template <typename T> void operator()(T t)" << endl;
}
};
// note can't specialize inline, have to declare outside of the class body
template<> void doh::operator()(int i)
{
cout << "template <> void operator()(int i)" << endl;
}
template<> void doh::operator()(bool b)
{
cout << "template <> void operator()(bool b)" << endl;
}
int main()
{
doh d;
int i;
bool b;
d(b);
d(i);
}
出力:
operator()(bool b)
template <> void operator()(int i)
上記の二重括弧の構文は非常に奇妙です。通常、私は演算子(bool b)を見ましたが、演算子()(bool b)はどのように動作しますか?最初の空()の使用は何ですか? – Jimm
@ Jimmメソッド名は 'operator()'で、1つのパラメータ 'bool b'をとります...これは関数呼び出し演算子です。私のコード例の 'main'を参照してください。' d(b) ' – stefanB