How to create a template function within a class? (C++)

后端 未结 4 1704
粉色の甜心
粉色の甜心 2020-11-30 16:45

I know it\'s possible to make a template function:

template
void DoSomeThing(T x){}

and it\'s possible to make a template

4条回答
  •  萌比男神i
    2020-11-30 17:16

    See here: Templates, template methods,Member Templates, Member Function Templates

    class   Vector
    {
      int     array[3];
    
      template  
      void  eqAdd(TVECTOR2 v2);
    };
    
    template 
    void    Vector::eqAdd(TVECTOR2 a2)
    {
      for (int i(0); i < 3; ++i) array[i] += a2[i];
    }
    

提交回复
热议问题