可能容易解决,但它很难找到一个解决这个模板特殊化:必须有一整套的参数
是否可以(部分)专门用于一整套的类型? 在示例中,“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