Code:
template<class T>
struct A {
void f1() {};
void f2() {};
};
template<>
struct A<int> {
void f2() {};
};
int main() {
A<int> data;
data.f1();
data.f2();
};
ERROR:
test.cpp: In function 'int main()':
test.cpp:16: error: 'struct A<int>' has no member named 'f1'
Basically, I only want to specialize one function and use the common definition for other functions. (In actual code, I have many functions which I don't want to specialize).
How to do this? Thanks!
Consider moving common parts to a base class:
You can even override
f1
in the derived class. If you want to do something more fancy (including being able to callf2
fromf1
code in the base class), look at the CRTP.