C++(template模板 && 具体化自定义数据类型)
C++(template模板 && 具体化自定义数据类型)
具体化自定义数据类型
class Person
{
public:
Person() {}
~Person() {}
Person(int age) :m_Age(age){}
int m_Age;
};
template<class T>
bool mycompare(T &a, T &b)
{
if (a == b)
return true;
return false;
}
// 通过具体化自定义数据类型,解决上述问题
template<> bool mycompare<Person>(Person &a, Person &b) {
if (a.m_Age == b.m_Age)
return true;
return false;
}
浙公网安备 33010602011771号