爲什麼這不起作用?無法專用struct
template <class T>
struct Low;
template <>
struct Low<int> {};//Here I'm trying to specialize for int
int main()
{
Low<1> a;
}
爲什麼這不起作用?無法專用struct
template <class T>
struct Low;
template <>
struct Low<int> {};//Here I'm trying to specialize for int
int main()
{
Low<1> a;
}
Low<int> a;
將工作 - 你的模板需要型不是整體說法。
Low<1> a;
你的類模板Low
預計類型,而不是積分值!
如果你想用這種方式,你來定義類模板爲:
template <int N>
struct Low {};
這允許你寫Low<1>
,Low<2>
,Low<400>
等
如果你定義爲Low
as,
template <class T>
struct Low;
然後,在實例化它時,必須提供類型。例如,Low<char>
,Low<unsigned int>
等。
所以注意它們在每種情況下的定義以及它們是如何實例化的!
Low<1>
與Low<int>
之間的差異。
您需要編寫Low<1>
的專業化版,但這是不可能的,因爲原始模板將類型作爲第一個參數而不是值。
是的,公平點。 – 2011-04-03 11:28:10