题目是:做一个矩形的类,输入长度和宽度,然后求出面积. #include <iostream> using namespace std; class Rectangle //矩形类 { public: Rectangle(float w,float l);
float Area();
private: float width,length; }; //类的实现
Rectangle::Rectangle(float w,float l) {width=w;length=l;}
float Rectangle::Area() { return width*length; } //主函数实现 void main() { float width,length;
Rectangle a(width,length);
cout<<"please enter the length and width of the rectangle:"<<endl;
cin >> width >> length;
cout<<"The rectangle's area is "<<a.Area()<<endl; } 在用圆类的时候,就是只有一个参数的时候就可以得到结果,但是这有两个参数的时候,编译有两个 warning: local variable'length' used without having been initialized和 local variable 'width' used without having been initialized 不懂这是怎么回事,帮我改正一下吧,谢谢!!!
[此贴子已经被作者于2005-10-18 13:08:36编辑过]