How to specialize only some members of a template class?

后端 未结 3 1113
忘了有多久
忘了有多久 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:21

    When we declare specializations for a template class, we must also define all its members, even those exactly equal to the generic template class, because there is no inheritance of members from the generic template to the specialization. So, in your specialization you have to implement void f1(); too.

提交回复
热议问题