#include<iostream>
using namespace std;
#include <string>
template<class T>
T max(T a, T b)
{
return a > b ? a : b;
}
class MM
{
public:
MM(string name, int age) :name(name), age(age){}
string getname()
{
return name;
}
int getage()
{
return age;
}
bool operator>(const MM& object//要>号重载,因为对象不能直接判断;
{
return this->age > object.age;
}
protected:
string name;
int age;
};
void testuserdata()
{
cout << max(MM("name2", 18), MM("name1", 28)).getname() << endl;//T:MM,返回是一个对象
cout << max(MM("name2", 18), MM("name1", 28)).getage() << endl;//T:MM
}
int main()
{
cout << "操作自定义类型" << endl;
testuserdata();
while (1);
return 0;
}