2

例えば:

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. */
}

動作しないようです。どうやってするの?ありがとう。

4

1 に答える 1

2

クラス テンプレートの明示的な特殊化は、通常のクラスに似ています (完全にインスタンス化されているため、パラメトリック型ではありません)。したがって、外側は必要ありません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. */
}
于 2013-07-06T14:05:50.867 に答える