- 1
- 0
- 约 38页
- 2016-11-26 发布于河南
- 举报
第 8 章 从结构到类和对象
void main( ){ Rectangle r; r.width=45; r.length=54.2; coutthe area of rectangle is r.Area()endl; coutthe perimeter of rectangle is r.Perimeter()endl; } 非法访问 私有成员! Length和width怎样才能获取数据呢? #includeiostream.h class Rectangle{ float length,width; public: void SetWidth(float newWidth) { width=newWidth; } void SetLength(float newLength) { length=newLength; } float Area( ) { return length*width; } float Perimeter( ) { return 2*(length+width); } }; 例: 设置两个公共成员函数来对这2个私有变量操作 void main(
原创力文档

文档评论(0)