例えば:
template<unsigned number>
struct A
{
template<class T>
static void Fun()
{}
};
template<>
struct A<1>
{
template<class T>
static void Fun()
{
/* some code here. */
}
};
そして、A <1> :: Fun()を専門にしたい
template<>
template<>
void A<1>::Fun<int>()
{
/* some code here. */
}
動作していないようです。どうやるか?ありがとう。
クラステンプレートの明示的な特殊化は、通常のクラスに似ています(完全にインスタンス化されるため、パラメトリックタイプではありません)。したがって、外側は必要ありませんtemplate<>
:
// template<> <== NOT NEEDED: A<1> is just like a regular class
template<> // <== NEEDED to explicitly specialize member function template Fun()
void A<1>::Fun<int>()
{
/* some code here. */
}
同様に、メンバー関数Fun
が関数テンプレートではなく、通常のメンバー関数である場合は、次のものはまったく必要ありませんtemplate<>
。
template<>
struct A<1>
{
void Fun();
};
void A<1>::Fun()
{
/* some code here. */
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加