#include <iostream>
using namespace std;
class stone{
public:
stone(int weight = 0) : m_weight(weight){};
bool operator< (const stone &rhs) const {
return m_weight < rhs.m_weight;
}
int getValue(){
return m_weight;
}
private:
int m_weight = 0;
};
template <class T>
inline
const T& Mymin(const T &a, const T &b)
{
return a < b ? a : b;
}
int main()
{
stone a(10), b(20), c;
c = Mymin<stone>(a, b);
cout << c.getValue() << endl;
return 0;
}
函数模板(参数为类)运算符重载
最新推荐文章于 2024-07-20 22:49:13 发布