See following code. The first MyClass<> has two functions (func1 and func2). Then I would like to do some special thing for MyClass in func1 but not func2. It looks like I have to type code for func2 again. I am wondering if there is a way to work this around? Thanks
#include <iostream>
using namespace std;
template <class T>
class MyClass {
public:
void func1(){
cout<<"default: func1"<<endl;
}
void func2(){
cout<<"default: func2"<<endl;
}
private:
T haha;
};
template <>
class MyClass<double> {
public:
void func1(){
cout<<"special: func1"<<endl;
}
};
int main()
{
MyClass<int> intclass;
intclass.func1();
intclass.func2();
MyClass<double> doubleclass;
doubleclass.func1();
doubleclass.func2(); // error 'class MyClass<double>' has no member named 'func2'
return 0;
}