小编ano*_*non的帖子

如何只对模板类的某些成员进行专门化?

码:

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

};

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


int main() {
  A<int> data;
  data.f1();
  data.f2();
};
Run Code Online (Sandbox Code Playgroud)

错误:

test.cpp: In function 'int main()':
test.cpp:16: error: 'struct A<int>' has no member named 'f1'
Run Code Online (Sandbox Code Playgroud)

基本上,我只想专门化一个函数并使用其他函数的通用定义.(在实际代码中,我有许多我不想专门研究的函数).

这该怎么做?谢谢!

c++ templates partial-specialization template-specialization

10
推荐指数
2
解决办法
3255
查看次数