我目前正在重构一些代码,明确地专门化了具有两个模板参数的类模板的成员函数。部分专门化的成员函数实现
template <class S, class T>
class Foo
{
void bar();
};
template <class S, class T>
void Foo<S, T>::bar()
{ /* Generic stuff */ }
template <>
void Foo<SomeType, SomeType>::bar()
{ /* Some special function */ }
现在我增加了一些更多的模板参数,因此该类现在看起来是这样的:
template <class S, class EXTRA0, class T, class EXTRA1>
class Foo
{
void bar();
};
这两个额外的参数只需添加类型定义上我的课,所以运行时功能不真的改变了。有什么办法可以保持酒吧的(现在部分)专门的实施?我似乎无法弄清楚它的语法,我有一种预感可能是不可能的。
编辑:我在寻找类似:
template <class EXTRA0, class EXTRA1>
void foo<SomeType, EXTRA0, Sometype, EXTRA1>::bar()
{
/* specialized implementation */
}
这似乎并没有编译..
据我所知,你还记得正确的:你不能部分专门功能,只有类型。 – Simone 2011-02-07 10:17:54
@Simone它的工作,至少在g ++。 – UmmaGumma 2011-02-07 10:22:05