//模版类中有模版函数偏特化, 有模版泛化, 全特化, 重载
//模版函数调用优先级: 全特化, 特化, 泛化
//泛化
template <typename T,typename U>
struct TC
{
TC()
{
cout << "TC泛化版本构造函数" << endl;
}
void functest1()
{
cout << "functest1泛化版本" << endl;
}
static int m_stc; //声明一个静态成员变量
};
template <typename T, typename U>
int TC<T,U>::m_stc = 50; //定义静态成员变量, 偏特化
//template <>
int TC<double, int>::m_stc = 100;//定义为全特化
template <> //全特化:所有类型模板参数都yoghurt具体类型代表,所以<>里就空了
struct TC<int, int>
{
TC()
{
cout << "TC<int,int>特化版本构造函数" << endl;
}
void functest1();
{
cout << "functest1特化版本" << endl;
}
void functest2();
{
cout << "functest2特化版本" << endl;
}
};
//-------------------------
template <typename U>
struct TC<float, U>
{
TC()
{
cout << "TC<float,U>偏特化版本构造函数" << endl;
}
void functest1();
};
template <typename U>
void TC<float, U>::functest1()
{
cout << "TC<float,U>::functest1偏特化版本" << endl;
}
//-------------------------
template <typename T, typename U>
struct TC<const T, U*>
{
TC()
{
cout << "TC<const T,U*>偏特化版本构造函数" << endl;
}
void functest1();
};
template <typename T, typename U>
void TC<const T, U*>::functest1()
{
cout << "TC<const T,U*>::functest1偏特化版本" << endl;
}
///////////////////////////////////////////////////////////////////////////////
//缺省参数(只能在泛化版本中才能有, 特化版本是没有的)
template <typename T,typename U = int>
struct TC
{
TC()
{
cout << "TC泛化版本构造函数" << endl;
}
void functest1()
{
cout << "functest1泛化版本" << endl;
}
static int m_stc; //声明一个静态成员变量
};