#include<iostream>
#include<vector>
using namespace std;
template<typename T1, typename T2>
class MyClass
{
public:
MyClass() {
cout << "主模板" << endl;
}
};
template<typename T>
class MyClass<T, T>
{
public:
MyClass() {
cout << "偏特化<T, T>" << endl;
}
};
template<typename T>
class MyClass<T, int>
{
public:
MyClass() {
cout << "偏特化<T, int>" << endl;
}
};
template<typename T1, typename T2>
class MyClass<T1*, T2*>
{
public:
MyClass() {
cout << "偏特化<T1*, T2*>" << endl;
}
};
int main() {
MyClass<float, float>c1;
MyClass<float, int>c2;
MyClass<int*, float*>c3;
MyClass<int, float>c4;
//MyClass<int, int>c5;//具有二义性,无法通过编译
}
结果: