加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 本身就是模板的专业化

发布时间:2020-12-16 03:15:57 所属栏目:百科 来源:网络整理
导读:我有一个模板类,我有一些专长. 但下一个专业化是一个模板本身.你如何指定: templatetypename Tclass Action{ public: void doStuff() { std::cout "Genericn"; }}// A specialization for a persontemplateclass ActionPerson{ public: void doStuff() { s
我有一个模板类,我有一些专长.
但下一个专业化是一个模板本身.你如何指定:
template<typename T>
class Action
{
    public: void doStuff()  { std::cout << "Genericn"; }
}

// A specialization for a person
template<>
class Action<Person>
{
    public: void doStuff()  { std::cout << "A Personn";}
}


// I can easily specialize for vectors of a particular type.
// But how  do I change the following so that it works with all types of vector.
// Not just `int`
template<>
class Action<std::vector<int> >
{
    public: void doStuff()  { std::cout << "A Generic Vectorn";}
}

解决方法

琐碎的部分专业化?
template <typename T>
class Action<std::vector<T>> {
public:
  void doStuff() { std::cout << "A Generic Vectorn"; }
};

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读