假设我有一个模板类
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
};
它的工作方式与常规特化一样,但有一个额外的模板参数。
关于c++ - 模板的总类特化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4686445/