class Rectangle 日日日日日量日日日日a■ 默认情况下类的成员是私有 float width;;的,而结构体trme中的成 float length:员是公有的 float area void setData(float, float); void calcArea(; float getwidth(; float getLength(; float getArea()
class Rectangle { float width; float length: float area; void setData(float, float); void calcArea( ); float getWidth( ); float getLength( ); float getArea( ); }; 默认情况下类的成员是私有 的,而结构体(struct)中的成 员是公有的
32类的基本概念(续) 为了使类的成员能够在类外面被访问,其 成员必须定义为 public ° Example:
7 3.2 类的基本概念(续) • 为了使类的成员能够在类外面被访问,其 成员必须定义为public. • Example:
class Rectangle private float width: float length: float area: public: void setData(float, float); void calcArea(; float getwidth ( float getlength(; float getArea()
class Rectangle { private: float width; float length: float area; public: void setData(float, float); void calcArea( ); float getWidth( ); float getLength( ); float getArea( ); };
class Rectangle public: void setData(float, float); oid calcArea(; float getwidth( float getlength(; float getArea(; rivate pI float width float length: float area:
class Rectangle { public: void setData(float, float); void calcArea( ); float getWidth( ); float getLength( ); float getArea( ); private: float width; float length: float area; };
class Rectangle private float width public: void setData (float, float); void calcArea(; float getWidth (; float getLength(; float getArea(; private float length: float area:
class Rectangle { private: float width; public: void setData(float, float); void calcArea( ); float getWidth( ); float getLength( ); float getArea( ); private: float length: float area; };