【发布时间】:2011-02-10 10:01:27
【问题描述】:
代码:
template<class T>
struct A {
void f1() {};
void f2() {};
};
template<>
struct A<int> {
void f2() {};
};
int main() {
A<int> data;
data.f1();
data.f2();
};
错误:
test.cpp: In function 'int main()':
test.cpp:16: error: 'struct A<int>' has no member named 'f1'
基本上,我只想专门化一个函数,而对其他函数使用通用定义。 (在实际代码中,我有很多我不想专门化的函数。
如何做到这一点?谢谢!
【问题讨论】:
标签: c++ templates template-specialization partial-specialization