2010-09-17 67 views

回答

2

的也許是因爲這樣的事情:

template <typename T> 
struct foo 
{ 
    template <typename U> 
    struct bar 
    { 
     typedef U type; 
    }; 
}; 

template <typename T> 
struct foo<T>::bar<int> // imaginary 
{ 
    typedef void type; 
}; 

template <> 
struct foo<float> 
{ 
    template <typename U> 
    struct bar 
    { 
     typedef U* type; 
    }; 
}; 

// is it void [foo<T>::bar<int>] or 
// int* [foo<float>::bar<U>]? 
typedef foo<float>::bar<int>::type ambiguous; 

一個明智的解決辦法是說:「我們會讓整個事情明確的」。

+1

+1。甚至可能是'foo '根本沒有內部類型的'bar'。 – 2010-09-17 08:01:40

+0

這個答案引發了一個問題,但爲什麼部分專門化'bar' *是被允許的:'template template struct foo :: bar {typedef void type; };對於需要*兩個*參數的'bar'來說都沒問題。現在,如果你做'foo :: bar :: type',你會得到相同的「歧義」:) – 2010-09-17 09:51:17

+0

@Johannes:哼,那我就給你吧。 :) 這就是我得到的。 – GManNickG 2010-09-17 14:38:44