How to specialize only some members of a template class?

后端 未结 3 1120
忘了有多久
忘了有多久 2020-12-29 12:44

Code:

template
struct A {
  void f1() {};
  void f2() {};

};

template<>
struct A {
  void f2() {};
};


int main() {
  A<         


        
3条回答
  •  清酒与你
    2020-12-29 13:01

    Would this help:

    template
    struct A
    {
      void f1()
      {
        // generic implementation of f1
      }
      void f2()
      {
        // generic implementation of f2
      }
    };
    
    template<>
    void A::f2()                                                               
    {
      // specific  implementation of f2
    }
    

提交回复
热议问题