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;
}

posted on 2021-04-26 10:32  lodger47  阅读(391)  评论(0)    收藏  举报

导航