這是一個類的模板
template <typename T, unsigned int size>
class Foo {
T myarray[size];
//other code (doesn't matter for the example)
}
我想為它做一個模板專業化。例如,我定義了class Bar. 所以我想專攻class Bar,但我想保留unsigned int size。我怎么做?
template <>
class Foo<Bar, unsigned int> { //throws error "type name not allowed" for unsigned int
Bar myarray[size];
//other code
}
uj5u.com熱心網友回復:
這稱為部分模板特化:
template<unsigned int size>
class Foo<Bar, size> {
Bar myarray[size];
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/515143.html
標籤:C 模板模板专业化
上一篇:定義函式引數數量的C 模板
下一篇:如何簡化可變引數模板函式?
