嗨,任何人都可以解释部分模板模板专业化的正确语法是什么?甚至有可能吗?任何帮助深表感谢
template < typename A >
class X
{
};
template < typename B >
class Y
{
};
template < template< typename > class U, class T >
class Z
{
// there are other methods in class which i don't want to replicate
void func(); // want to specialize this for class X
};
template < template< typename > class U, class T >
void Z< U, T >::func()
{
std::cout << " this is done ";
}
// specialize this for X
template < template< typename > class U, class T >
void Z< X, T >::func()
{
}
您不能仅对类模板的一部分进行专门化处理。当部分专门化一个类模板时,您需要提供整个声明,而不仅仅是一个函数。
而且,您不能部分专门化功能模板。
您也许可以通过继承来做您想做的事情。您可以将共享方法收集到基类中,然后为带有异常的方法的部分专门化定义模板化派生类。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句