在C++中声明一个类的方法。
一般数据是私有的,方法是public的。这些方法是对数据的操作。
class Rectangle
{
private:
float length;
float width;
public:
Rectangle(float leng=0, float width=0);
float getLength();
float getWidth();
void setLength(float length) ;
void setWidth(float width) ;
};
Rectangle::Rectangle(float leng,float wid)
{
length=leng;
width=wid;
}
float Rectangle::getLength()
{
return length;
}
float Rectangle::getWidth()
{
return width;
}
void Rectangle::setLength(float length)
{
length=length;
}
void Rectangle::setWidth(float width)
{
width=width;
}