简单的template class定义为:
template
class A
{
public:
A(T a){
cout<<a<<endl;
}
};
int main()
{
A a(1);
};
[以下是更为复杂的逻辑,有两个typename,其中根据第二个typename,定义不同的class进行不同逻辑的处理]
#include
#include
using namespace std;
template <typename B, typename D>
class A;
class C
{
};
template
class A<B, C>
{
public:
A(B v){
cout<<“A Construct C”<<endl;
cout<<v<<endl;
}
};
class D
{
};
template
class A<B, D>
{
public:
A(B v){
cout<<“A Construct D”<<endl;
cout<<v<<endl;
}
};
int main()
{
cout<<“test”<<endl;
A<int, C> v(1);
A<int, D> v1(2);
return 0;
}