2014-05-08 80 views
0

我讀這裏給出了答案:https://stackoverflow.com/a/23550519/1938163與類模板偏特

,我不知道爲什麼最後一行是一個模板結構的偏特

template<typename T> MyClass { public: }; 

template <typename T> struct Foo {void foo() {}}; 
template<> struct Foo<int> {void foo() { std::cout << "fooint";} }; 

// Why is this a partial specialization? 
template<typename T> struct Foo< MyClass<T> > {void foo() {std::cout << "foo myclass";} }; 

我認爲部分專業化包括完全替代參數參數

template <typename T, typename G> struct FooBar {}; 

template <typename G> struct FooBar<int, G>{}; // Partial specialization 

回答

1

全特化是指當模板參數全部被具體類型替換並且模板參數列表爲空時。 MyClass<T>不具體;和

template<typename T> struct Foo<MyClass<T>> { ... }; 

它仍然被T參數化和模板參數列表中仍然包含T。例如,

template<> struct Foo<MyClass<int>> { ... }; 

將是Foo一個完整的專業化比Foo<MyClass<T>>更加專業化。