可能容易解決,但它很難找到一個解決這個模板特殊化:必須有一整套的參數
是否可以(部分)專門用於一整套的類型? 在示例中,「Foo」應僅部分專用於(T,int)和(T,double),只有一個模板定義。
我可以做的是爲(T,int)定義一個專門化。見下文。但是,它應該是(T,int)和(T,double)只有一個函數定義(無代碼加倍)。
template <typename T,typename T2>
struct Foo
{
static inline void apply(T a, T2 b)
{
cout << "we are in the generic template definition" << endl;
}
};
// partial (T,*)
template <typename T>
struct Foo<T, int > // here something needed like T2=(int, double)
{
static inline void apply(T a, T2 b)
{
cout << "we are in the partial specialisation for (T,int)" << endl;
}
};
任何想法如何用(T,int)和(T,double)部分專門化一個模板定義?
編譯器怎麼可能知道該怎麼做?它如何知道你想要打印''部分雙精度''等等? – 2011-04-17 16:44:48
輸出僅用於瞭解使用哪個函數定義。 – ritter 2011-04-17 17:04:39
哦,我現在明白了。 – 2011-04-17 17:06:03