繁体   English   中英

如何为一个类专门化模板template参数?

[英]How to specialize template template parameter for a class?

我有一个模板课

template <class T>
struct TypeText {
    static const char *text;
};

以及“文本”成员的几个专业化:

template <> const char* TypeText<int>::text = "INT";
template <> const char* TypeText<long>::text = "LONG";

如何在没有有关AB先验知识的情况下为std::vector<A,B>实现专门化? 是否可以将std::vector<A,B>SomeOtherClass<A,B>

以下内容不起作用:

template <>
template <class T, class A>
const char* TypeText< std::vector<T,A> >::text = "vector";

您可以为std::vector提供部分模板专业化

template <class T>
struct TypeText<std::vector<T>> {
    static const char *text;
};
template <class T>
const char* TypeText<std::vector<T>>::text = "vector";

然后使用它,例如:

...TypeText<std::vector<int>>::text...    // "vector"
...TypeText<std::vector<long>>::text...   // "vector"

生活

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM