Writing variadic template constructor

前端 未结 4 744
无人共我
无人共我 2021-02-02 10:38

Recently I asked this question but now I would like to expand it. I wrote the following class:

template 
class X{
public:
    vector v;
          


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-02-02 11:24

    template 
      X(T n, Rest... rest) {
       add(rest...);
     }
    
    //Just another member function
    template
      void add(T n) {
        v.push_back(n);
     }
      template
       void add(T n, Rest... rest) {
         v.push_back(n);
         add(rest...);
    
     }
    

提交回复
热议问题