天天看點

C++ typedef的繼承問題

template <class T1, class T2>
struct base1
{
    typedef T1 first_type;
    typedef T2 second_type;
};

template <class T1, class T2>
struct sub1 : public base1<T1, T2>
{
    typename base1<T1, T2>::first_type a;
    typename base1<T1, T2>::second_type b;
};

struct base2
{
    typedef short first_type;
    typedef long second_type;
};
struct sub2 : public base2
{
    first_type a;
    second_type b;
};

int main()
{
    sub1<short, long> s1;
    sub2 s2;

    return 0;
}