簡體   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