找错
songk 2002-02-05 05:43:26 #include <iostream>
using namespace std;
template <class Type>
Type mymin(Type a, Type b)
{
return a < b ? a : b;
}
class rect
{
friend ostream& operator<<(ostream& os, const rect& rhs);
public:
rect(int w, int h) : _w(w), _h(h)
{ _area = _w * _h; }
bool operator<(const rect& rhs) const
{ return _area < rhs._area; }
private:
int _w, _h, _area;
};
ostream& operator<<(ostream& os, const rect& rhs)
{
os << '(' << rhs._w << ',' << rhs._h << ')' << endl;
return os;
}
int main(int argc, char* argv[])
{
cout << mymin(10, 20) << endl;
cout << mymin(30.0, 20.0) << endl;
rect r1(3,5), r2(5,7);
cout << mymin(r1, r2) << endl;
return 0;
}