[英]total class specialization for a template
假设我有一个模板类
template <typename T>
struct Widget
{
//generalized implementation
}
但我想完全专注..对于一个接受参数的模板?
template <>
struct Widget< TemplateThatAcceptsParameter<N> >
{
//implementation for Widget for TemplateThatAcceptsParameterN
//which takes parameter N
}
怎么去做这个?
这称为部分特化 ,可以这样编码:
template <typename T>
struct Widget
{
//generalized implementation
};
template <typename N>
struct Widget< TemplateThatAcceptsParameter<N> >
{
//implementation for Widget for TemplateThatAcceptsParameterN
//which takes parameter N
};
它的工作方式与常规特化相似,但有一个额外的模板参数。
template < typename N >
struct Widget< template_thing<N> >
{
...
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.