[英]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.