【问题标题】:Template specialization with another template使用另一个模板的模板特化
【发布时间】:2016-12-05 11:44:20
【问题描述】:

假设我有两个模板类

template < class T >
class Foo
{
    /**/
};

和

template < class T >
class Bar
{
     /**/
};

我怎样才能用Bar&lt;T&gt; 专门化Foo ?? 语法是什么?? 是吗

template<>
template<class T>
class Foo<Bar<T>>
{ /**/ };

或

template<class T>
class Foo<Bar<T>>
{ /**/ };

或任何其他语法??

【问题讨论】:

  • template&lt;typename T&gt; class Foo&lt;Bar&lt;T&gt;&gt; 是正确的语法。
  • 你试过了吗? ideone.com/gTorRO

标签: c++ templates template-specialization template-classes


【解决方案1】:

语法是最后一个:

template<class T>
class Foo<Bar<T>>
{
     /* Your implementation of this partial specialization. */
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-05
    • 2020-11-15
    • 2015-02-19
    • 1970-01-01
    相关资源
    最近更新 更多