代码如下:
#include
using namespace std;
class Rectangle {
public:
Rectangle(int length = 1.0, int width = 1.0) : l(length), w(width) {
}
Rectangle(const Rectangle& other) {
l = other.l;
w = other.w;
}
friend ostream& operator<<(ostream& out, const Rectangle& rect) {
out << "(" << rect.l << "," << rect.w << ")";
return out;
}
private:
float l;
float w;
};
int main()
{
Rectangle rect1;
cout << rect1 << endl;
Rectangle rect2(2, 3);
cout << rect2 << endl;
Rectangle rect3 = rect2;
cout << rect3 << endl;
system("pause");
return 0;
}