#include <iostream>
using namespace std;
template <class Type> class MyClass{
Type p1;
public:
MyClass(Type p){
cout << "from the generic class conbstructor"<<endl;
p1 = p;
}
void whatYouGot(){
cout << p1<<endl;
}
};
template <> class MyClass <int>{
int p1;
public:
MyClass(int p){
p1 = p;
cout << "from the specific integer version class conbstructor"<<endl;
}
void whatYouGot(){
cout << p1<<endl;
}
};
int main()
{
MyClass <string> ob1("anil");
MyClass <int> ob2(22);
ob1.whatYouGot();
ob2.whatYouGot();
return 0;
}
沒有留言:
張貼留言