How to correctly initialize member variable of template type?

前端 未结 2 2033
孤独总比滥情好
孤独总比滥情好 2020-11-29 05:11

suggest i have a template function like following:

template
void doSomething()
{
    T a; // a is correctly initialized if T is a class with a         


        
2条回答
  •  北海茫月
    2020-11-29 05:58

    Class template field in C++11 has the same syntax:

    template 
    class A {
      public:
        A() {}
        A(T v) : val(v) {}
      private:
        T val{};
    };
    

提交回复
热议问题