1

テンプレートクラス内で宣言された内部クラスを特殊化することは可能ですか?多かれ少なかれ次の例のように(これは機能しません):

template<unsigned N>
class Outer {
    struct Inner {
        typedef int Value;
    };
    typedef typename Inner::Value Value;
};

template<>
struct Outer<0>::Inner {
    typedef float Value;
};
4

2 に答える 2

3

それはできますが、あなたがしようとするのとは異なります。外側の型全体を特殊化する必要があります。

template<>
struct Outer<0>
{
    struct Inner {
        typedef float Value;
    };
    typedef float Value;
};
于 2012-05-26T21:25:49.933 に答える
0

私が見つけた最善の解決策は、Inner外に移動することです。

template<unsigned N>
struct Inner {
    typedef int Value;
};

template<>
struct Inner<0> {
    typedef float Value;
};

template<unsigned N>
class Outer {
    typedef typename Inner<N>::Value Value;
};
于 2012-05-26T21:35:12.003 に答える