this->age = age;
this->name = name;
}
public:
string name;
int age;
};
template<class T>
void myfunc(T &a, T &b)
{
if (a > b)
{
cout << "a>b" << endl;
}
else
{
cout << "a<=b" << endl;
}
}
//不建议具体化函数模版,因为没有通用性
//具体化函数模版,注意上面的函数模版要有,才能具体化
template<>void myfunc<Maker>(Maker &a, Maker &b)
{
cout << "函数模版的具体化" << endl;
if (a.age > b.age)
{
cout << "a>b" << endl;
}
else
{
cout << "a<=b" << endl;
}
}
void test02()
{
Maker m1("aaa", 10);
Maker m2("bbb", 20);
myfunc(m1, m2);
}
int main()
{
test02();
system("pause");
return EXIT_SUCCESS;
}
参考资料
参考资料来源于黑马程序员
|