模板的总类专门化 [英] 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
}
这是怎么做的?
推荐答案
部分特化,并且可以这样编码:
This is called a partial specialization and can be coded like this:
template <typename T>
struct Widget
{
//generalized implementation
};
template <typename N>
struct Widget< TemplateThatAcceptsParameter<N> >
{
//implementation for Widget for TemplateThatAcceptsParameterN
//which takes parameter N
};
它像一个常规的专业化,但有一个额外的模板参数。
It works just like a regular specialization, but has an extra template argument.
这篇关于模板的总类专门化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文